puppet node hostname

ぃ、小莉子 提交于 2019-12-04 08:27:45

问题


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?


回答1:


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




回答2:


Entering the following command into your terminal will return variables available in your erb files:

facter --puppet



回答3:


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 FAQ).




回答4:


Apparently you can now use

<%= fqdn %> 

and get the DNS reverse name.

If you need to lowercase it, use

<%= fqdn.downcase %>



回答5:


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).



来源:https://stackoverflow.com/questions/4428153/puppet-node-hostname

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!