Re: [Puppet Users] Does anyone know how to evaluate a node hostname in nodes.pp file?

69 views
Skip to first unread message

Ramin K

unread,
Nov 1, 2012, 4:38:27 PM11/1/12
to puppet...@googlegroups.com
On 11/1/2012 12:12 PM, romario nguyen wrote:
> Does any one know how to evaluate a node hostname in the nodes.pp file?
> for example something like this..
> node 'node1.com', 'node2.com', 'node3.com' {
> case node.name {
> 'node1.com' : { include solaris }
> 'node2.com' : { include redhat }
> 'node3.com' : { include aix }
> default: { include generic }
> }
> Much appreciated your feedback. Thanks!

You might consider letting regex and facter do more of the work for you.

node /^node\d+\.yourdomain\.com$/ {

include $::osfamily # or the more specific $::operatingsystem
}

However if you were to build a case around the node name you can use
$::hostname or $::clientcert. I use clientcert more often because the
hostname is not always correct through provisioning in my system. Same
syntax either way.

node /^fe\d+\.(ord|lax|sfo)\.mydomain\.com/ inherits basenode {

include hostgroup::frontend

case $::clientcert {
/^fe02(.*)/: { # matching any server named fe02
cron::listings { 'listings':
cron_env => 'production_migrate',
cron_user => 'deploy',
}
}
default: {}
}

}

Ramin

jcbollinger

unread,
Nov 2, 2012, 9:58:02 AM11/2/12
to puppet...@googlegroups.com


On Thursday, November 1, 2012 3:38:38 PM UTC-5, Ramin K wrote:
On 11/1/2012 12:12 PM, romario nguyen wrote:
> Does any one know how to evaluate a node hostname in the nodes.pp file?
> for example something like this..
> node 'node1.com', 'node2.com', 'node3.com' {
>     case node.name {
>         'node1.com' : { include solaris }
>         'node2.com' : { include redhat }
>         'node3.com' : { include aix }
>         default: { include generic }
> }
> Much appreciated your feedback.  Thanks!

You might consider letting regex and facter do more of the work for you.


You don't even need that for the OP's original case.  Instead of grouping nodes and then trying to separate them out again, it would make more sense to avoid grouping them in the first place:

node 'node1.com' {
  include 'solaris'
}

node 'node2.com' {
  include 'redhat'
}

node 'node3.com' {
   include 'aix'
}

# Note: the default case in the OP's pseudocode
# would never have applied, but I infer that something
# like this was desired:
node default {
  include 'generic'
}


On the other hand, in direct answer to the OP's question, nodes.pp is a Puppet manifest just like any other, so you can access node facts there.  Facts are not dependent on node blocks (and indeed, node blocks are optional).  You can access nodes' hostnames via the $::hostname fact.


John

Reply all
Reply to author
Forward
0 new messages