English 中文(简体)
puppet node hostname
原标题:

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?

最佳回答

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

问题回答

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

facter --puppet

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

Apparently you can now use

<%= fqdn %> 

and get the DNS reverse name.

If you need to lowercase it, use

<%= fqdn.downcase %>

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





相关问题
How can one change a Windows 2000 computer name in .NET 2.0?

I m trying to change a computer s name (host name) on Windows 2000 using .NET 2.0. The computer is not joined to a domain. Windows XP and higher provides the WMI method Win32_ComputerSystem.Rename, ...

Get hostname from Rails controller

I am trying to get the hostname of the machine which a rails application is running on from the controller. What would be the best way to do this taking into account it should work on both windows ...

Get host name without using HttpRequest

I want to run a "background job" in my ASP.NET application (periodically, as separate thread). And I need host name (DNS name or IP) to do my tasks. The problem is that the HttpContext.Current may be ...

key value routing in Zend Framework Route

I m using a Hostname route to capture a subdomain and use as a category. I then chain a Router route for the controller, action and key/value pairs. $hostnameRoute = new ...

php - regex hostname extraction

I have been looking around for a regex expression that will spit out just the stackoverflow part and no www. or .com etc. All I could find was to check if the url s were valid... I have used php s ...

Setting hostname in IIS, include www?

I want to set the hostname for a website I m adding in IIS 7, however do I include the www in the hostname or not? because I want both www.mysite.com and mysite.com both to point to mysite on the ...

热门标签