Reputation: 11057
I've been trying to figure out how to get the node's name (knife bootstrap -N
) into a template. I've tried a dozen different ideas and haven't found anything that works yet. Does anyone know how to access this from a Chef recipe?
Also -- is there a way to list all of the variables available to a Chef recipe?
Upvotes: 23
Views: 35321
Reputation: 3292
A cleaner more concise way is shown on the Attributes wiki page:
node.name
Upvotes: 35
Reputation: 6079
To see all node specific attributes type command
knife node edit <name> -a
First level keys accessible with "node." prefix.
{
"name": "n1",
...
"hostname": "chef-n1",
"fqdn": "chef-n1.dan.lan",
"domain": "dan.lan",
"ipaddress": "192.168.4.4",
"macaddress": "52:54:00:72:E7:C5",
Upvotes: 5
Reputation: 541
You can use Chef::Config[:node_name]
in your recipe. I found this in the chef-client cookbook from Opscode.
Upvotes: 31