Small Mosaic


Categories:

/books
/career
/codinghorrors
/events
/geekstuff
/justdont
/languages
/languages/bash
/linkshot
/magazines
/meta
/misctech
/movies
/nottech
/operatingsystems
/operatingsystems/linux
/operatingsystems/linux/debian
/operatingsystems/solaris
/perl
/presentations
/programming
/python
/ruby
/security
/security/apache
/security/tools
/serversmells
/services
/services/dns
/sites
/specifications
/sysadmin
/testing
/tools
/tools/commandline
/tools/firefox
/tools/gui
/tools/network
/tools/online
/tools/online/greasemonkey
/tools/puppet
/unixdaemon

Archives:

July 20111
June 20112
May 20113
April 20112
March 20117
January 20111
December 20103
November 20103
August 20101
July 20101
June 20104
May 20102
April 20101
March 20108
February 20101
January 20102
Full Archives

Wed, 23 Sep 2009

Simplifying File Permissions in Puppet Manifests
I've been a user of Puppet for about three years now and while on a recent dig in to some of my older classes it was a little embarrassing to see lots of file types used like this:


  file { "/srv/whi/maps":
    ensure => present,
    source => "puppet://$servername/whi/maps.conf"
    owner  => whi,
    group  => whi,
    mode   => 644
  }
  file { "/srv/whi/elocs":
    ensure => present,
    source => "puppet://$servername/whi/eloc.conf"
    owner  => whi,
    group  => whi,
    mode   => 644
  }

Luckily as we get more experienced with a tool we can often go back and improve on the first steps. By using an explicit File { settings } inside a class you can assign a sensible set of defaults to all the instances of the same type that lack overriding settings. So we can shorten the previous example to -


File {
  owner => whi,
  group => whi,
  mode  => 644
}

file { "/srv/whi/maps":
  ensure => present,
  source => "puppet://$servername/whi/maps.conf"
}

file { "/srv/whi/elocs":
  ensure => present,
  source => "puppet://$servername/whi/eloc.conf"
}

While this isn't a huge win in raw characters typed (although in longer manifests they start to mount up) it does move all the common settings in to a single location (keeping us clear of DRY violations) and it leaves only the differences between file type definitions.

You can also apply those kind of settings (such as Exec { path => "path:list" } at the server level by including them in a top level file and then overriding them as needed in each module. If you do this then you need to be aware that any declared type that doesn't override it gets the global setting, which can lead to the odd action from afar head scratching.

Like this post? - Digg Me! | Add to del.icio.us! | reddit this!

Posted: 2009/09/23 22:16 | /tools/puppet | Permanent link to this entry | This entry and same date


books career codinghorrors events geekstuff justdont magazines meta misctech movies nottech operatingsystems/linux operatingsystems/linux/debian operatingsystems/solaris perl programming python ruby security security/apache security/tools serversmells services/dns sites sysadmin testing tools tools/commandline tools/firefox tools/gui tools/network tools/online tools/online/greasemonkey tools/puppet unixdaemon

Copyright © 2000-2010 Dean Wilson XML feed logo