[nycbug-talk] [OT] Puppet question

Edward Capriolo edlinuxguru at gmail.com
Sat Jan 22 13:16:34 EST 2011

On Sat, Jan 22, 2011 at 11:12 AM, Matt Juszczak <matt at atopia.net> wrote:
> Hi folks,
> I know many of you use puppet pretty often, so I'm wondering if anyone has a
> solution to the problem I have.
> We use multiple data centers but use the same puppet tree at each data
> center.  For the most part this works fine, but I have one issue: the
> /etc/ldap.conf (pushed by our basenode) as well as /etc/resolv.conf (pushed
> by our basenode) is different per data center.  We don't use environments,
> so there are a few ideas I have:
> 1) Parse the ${cn}, which contains the data center.  I'm not sure how to
> parse something inside puppet though - is that even possible to turn
> cn=xyz.dfw01.my-domain.net into just puppetVar: dataCenter=dfw01?
> 2) Set a puppetVar: dataCenter=xyz01 per node (I'm using external nodes).
> Since we use a launch script, this wouldn't be too hard - just add it to our
> template and populate for existing hosts.
> 3) Create a basenode per data center: basenode-dfw01, basenode-iad01, etc.
> However, this is about the same solution as adding a puppetVar to each
> node... so I'd avoid this one.
> Any thoughts on this from those who have good puppet expertise?
> Thanks,
> Matt
> _______________________________________________
> talk mailing list
> talk at lists.nycbug.org
> http://lists.nycbug.org/mailman/listinfo/talk

You should be able to use variables since they are evaluated at runtime

class ldap {
  file { "/etc/ldap.conf" :
    source => "puppet:///mainfiles/security/$ldap",
  file { "/etc/resolv.conf" :
    source => "puppet:///mainfiles/security/$resolve",

class ldap_ny inherits ldap {
  $ldap => "ny_ldap.conf",
  $resolv  => "ny_resolve.conf"

class ldap_tx inherits ldap {
  $ldap => "tx_ldap.conf",
  $resolv  => "tx_resolve.conf"

Then on nodes in texas include ldap_tx. In nodes in ny include ldap_ny.

Also the source of a file definition can be a list, and the list can
use variables so your can do per host overrides

source => [ "${fqdn}.txt', "standard.txt" ]

There are other more complex methods such as modules or definitions
that build the files based on variables.  However I like the file
method as it is less complex then making and debugging modules.

More information about the talk mailing list