How to use local variable of whitespace array in chef template resource

438 Views Asked by At

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"

1

There are 1 best solutions below

2
On

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