22
votes

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?

3

3 Answers

35
votes

A cleaner more concise way is shown on the Attributes wiki page:

node.name
30
votes

You can use Chef::Config[:node_name] in your recipe. I found this in the chef-client cookbook from Opscode.

5
votes

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",