Umesh Moghariya
Umesh Moghariya

Reputation: 3183

Pass a variable from bash into chef template

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

Upvotes: 1

Views: 262

Answers (1)

coderanger
coderanger

Reputation: 54267

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.

Upvotes: 1

Related Questions