romario nguyen
2012-Nov-01 19:12 UTC
[Puppet Users] Does anyone know how to evaluate a node hostname in nodes.pp file?
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 received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/Dx7Ue8P-yx4J. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ramin K
2012-Nov-01 20:38 UTC
Re: [Puppet Users] Does anyone know how to evaluate a node hostname in nodes.pp file?
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 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-Nov-02 13:58 UTC
Re: [Puppet Users] Does anyone know how to evaluate a node hostname in nodes.pp file?
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 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/vI4IForuNQ4J. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.