Paul Croarkin
Paul Croarkin

Reputation: 14675

Chef Template Does Not Evaluate chef_environment and name Correctly

knife node show -l my-node -F json

returns:

{
   "name": "my-node",
   "chef_environment": "test"
   ..
}

We have created a template, info.txt.erb:

node = <%= node %>
name = <%= node['name'] %>
chef_environment = <%= node['chef_environment'] %>

Our recipe:

template "#{app_dir}/info.txt" do
  source 'info.txt.erb'
  ...
end

After the chef run, the node has an info.txt file:

node = my-node
name =
chef_environment =

Why does the knife show <NODE> command return something different than what is evaluated by the template file? How can I change the template file to get the correct information?

Upvotes: 0

Views: 337

Answers (1)

coderanger
coderanger

Reputation: 54249

That should be node.name and node.chef_environment. They aren't attributes, so you can't use the attribute access syntax to get them.

Upvotes: 4

Related Questions