puppet node hostname

Michal Bryxí picture Michal Bryxí · Dec 13, 2010 · Viewed 44.2k times · Source

I'm using puppet to configure servers. I want to print current machine (node) name in *.erb template. There is hostname variable, but this holds puppetmaster hostname. Is there any good reference/list regarding to this topic?

Answer

Michal Bryxí picture Michal Bryxí · Dec 13, 2010

Seems like I have miss-looked somewhere. I can get(print) node-hostname simply by invoking following code in *.erb template:

<%= @hostname %>

Edit: As of Puppet 3, using local variables (i.e. hostname is deprecated; Puppet 4 will remove support for them entirely. The recommended way is to use instance variables (prefixed with @. So in this case, @hostname. Source