0

I am trying to use whitespace arrays in chef template, like below and when I run the chef-client to execute the recipe getting an error saying: option variables must be a kind of [Hash]! below is recipe file

abc = node['abc']
def1 = node['def']
abc_sit = abc['sit']
def_sit = def1['sit']
%w{abc_sit def_sit}.each do | client |
  template "/etc/#{client}.sh" do
   source 'tunnel.erb'
   owner 'root'
   group 'root'
   variables ("#{client}") --> At this line I am getting error
 end
end

The error I am getting when I run the chef-client:

option variables must be a kind of [Hash]! You passed "abc_sit"

Bill P
  • 3,622
  • 10
  • 20
  • 32
ravi
  • 1
  • 2
  • You cannot name a local variable `def` please update the question so it is at least valid ruby. Also `%w{abc_sit def_sit}` does not use your variables it converts this to strings so your output is `["abc_sit","def_sit"]` with no regard for those local variable definitions. https://stackoverflow.com/questions/1274675/what-does-warray-mean and https://simpleror.wordpress.com/2009/03/15/q-q-w-w-x-r-s/ should help with understanding the shortcut syntax – engineersmnky Sep 10 '18 at 15:44

1 Answers1

0

As it says, you have to pass in a Hash. Perhaps something like variables myclient: client and then <%= @myclient %> in the template.

coderanger
  • 52,400
  • 4
  • 52
  • 75
  • Hello, i want to use same template file for all the names declared in whiltespace array and want to dynamically call the client name from variables field – ravi Sep 10 '18 at 02:40
  • Yes, so you have to pass in a hash with the client name as a value, as I showed. – coderanger Sep 10 '18 at 03:21