erikcw
erikcw

Reputation: 11057

Node Name in Chef Template?

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

Answers (3)

jarrad
jarrad

Reputation: 3292

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

node.name

Upvotes: 35

Daniil Iaitskov
Daniil Iaitskov

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

Shuang Wu
Shuang Wu

Reputation: 541

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

Upvotes: 31

Related Questions