[Puppet-users] definitions v. plugins

esquid2 at gmail.com esquid2 at gmail.com
Thu Aug 16 15:46:21 CDT 2007


i was looking at the simple text recipes wiki:
http://reductivelabs.com/trac/puppet/wiki/SimpleTextRecipes

and based on that wrote something that can ensure a certain variable in a
config file is set to a specific value, using a specific delimiter as
requested (defaults to a space).  this seems to work great at managing all
sorts of unix and mac config files (sshd_config, hostconfig on macs).  right
now it's written as a definition, but it feels very hacky:

"""
define ensure_key_value($file, $key, $value, $delimeter = " ") {

  # append line if "$key" not in "$file"
  exec { "echo '$key$delimeter$value' >> $file":
    unless => "grep -qe '^$key[[:space:]]*$delimeter' -- $file",
    path => "/bin:/usr/bin"
  }

  # update it if it already exists...
  exec { "sed -i '' 's/^$key$delimeter.*$/$key$delimeter$value/g' $file":
    unless => "grep -xqe '$key[[:space:]]*$delimeter[[:space:]]*$value' --
$file",
    path => "/bin:/usr/bin"
  }
}
"""

having to shell out to echo, grep, sed just doesn't feel right (some of the
other recipes on that page shell out to perl (from within ruby remember!)).
seems like a new plugin type would be the right way to do all of these, but
i'm surprised such basic types do not already exist.  is there no extra
repository of custom types besides the ones that are included with puppet?

seems like all these types of simple text-file operations should be pretty
common and pretty core to the system, does everyone just shell out and
suppress that urge to vomit when they need to do this type of thing?  is it
something just waiting someone with time to do it the right way in ruby?

cheers,
|eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.madstop.com/pipermail/puppet-users/attachments/20070816/025421b9/attachment.html 


More information about the Puppet-users mailing list