Using template to set a variable in chef

161 views Asked by At

new to chef and trying to pass a long list of variables to a batch file run. Have thought of writing a list of these in a template and calling the template in the recipe i.e:

options = template "optionstemplate"

How does one set a variable using hashes from a template of in chef? Please do let me know if this is possible of if there is another way to do this.

1

There are 1 answers

1
coderanger On BEST ANSWER

While technically doable, this is very hard and not recommended. You should instead write some Ruby code to generate the options string you need. Maybe something like:

options = ''
node['mythingy']['options'].each do |key, value|
  options << " --#{key}=#{value}"
end