Pass a variable from bash into chef template

260 views Asked by At

In my chef recipe, I have a bash ruby block. I need some value generated from it passed to my templates. For example, the joke variable in here:

bash "create opal user" do
 code <<-EOH                                                                                                                                                
  joke='my funny joke'
  echo $joke
 EOH
end


template '/joke.txt' do
  source 'joke.txt.erb'
  variable(joke:"#{joke}")
end
1

There are 1 answers

0
coderanger On BEST ANSWER

Answered in IRC, Chef doesn't work like this in general. The shell_out helper can sometimes be used but overall you should try to not structure your recipes this way.