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?
5 Answers
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

- 1,339
- 1
- 11
- 13

- 1,166
- 1
- 11
- 18
-
ah exactly, I was really puzzled, because in my case for "fqdn" I get the full hostname (like "myhost.acnemcom"), while for "hostname" I get the short version (the one returned by the command hostname -s) , like "myhost". In no case I get the puppetmaster host. – Pierluigi Vernetto Sep 12 '14 at 16:48
Entering the following command into your terminal will return variables available in your erb files:
facter --puppet

- 1,286
- 14
- 20
-
1This answer shows that I don't want 'hostname' but 'fqdn' instead form my application. – Niels Basjes Jan 16 '14 at 10:51
Yes to all the above; you may also find the fqdn
variable useful, depending on what you're up to.
If you DO find yourself needing the puppet master server's info in a template, you can use the variables servername
, serverip
, and serverversion
(From the Puppet docs).

- 909
- 4
- 16

- 111
- 1
- 3
Apparently you can now use
<%= fqdn %>
and get the DNS reverse name.
If you need to lowercase it, use
<%= fqdn.downcase %>

- 10,763
- 7
- 51
- 69

- 136
- 3
Do note though, this is the hostname rather than the node name (which you originally asked for). In 99% of cases, these will be the same. AFAIK there isn't a way to get the actual node name in templates (and if there is, I'd love to hear it).

- 386
- 3
- 3