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 _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
On Thu, Aug 16, 2007 at 01:46:21PM -0700, esquid2@gmail.com wrote:> 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?There''s one floating around, but I don''t think it''s got many native Ruby types in it.> 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?I''ve tried re-writing the ''replace_line'' define as a native type, and got nowhere. (I''ve also tried writing Nagios-related types and an rsync file transfer type, neither of them have gotten off the ground). I find that the documentation for writing types and providers, while fine if you want to rewrite an existing type, isn''t good enough to properly reason about how to use the API in new and interesting ways. - Matt
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Friday 17 August 2007, Matthew Palmer wrote:> On Thu, Aug 16, 2007 at 01:46:21PM -0700, esquid2@gmail.com wrote: > > 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? > > There''s one floating around, but I don''t think it''s got many native Ruby > types in it.I have quite a lot of modules at git://git.black.co.at/manifests/, but non of them are native ruby types.> > 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? > > I''ve tried re-writing the ''replace_line'' define as a native type, and got > nowhere. (I''ve also tried writing Nagios-related types and an rsync file > transfer type, neither of them have gotten off the ground). I find that > the documentation for writing types and providers, while fine if you want > to rewrite an existing type, isn''t good enough to properly reason about how > to use the API in new and interesting ways.Since replace_line is very procedural, it is not a good fit for a puppet type. A better model would be something like my backuppc::setting define[1], which directly models "this key should have that value": |45 backuppc::setting { PingMaxMsec: val => "40"; } It''s just way too easy for me to implement such things internally by calling out to perl, where it is a one-an-a-half liner, instead of going the whole ruby way. I do have to acknowledge though, that it suck mightly from a general quality-of-implementation point of view :-( [1] http://git.black.co.at/?p=manifests.git;a=blob;f=modules/backuppc/manifests/init.pp;hb=HEAD Regards, David - -- The primary freedom of open source is not the freedom from cost, but the free- dom to shape software to do what you want. This freedom is /never/ exercised without cost, but is available /at all/ only by accepting the very different costs associated with open source, costs not in money, but in time and effort. - -- http://www.schierer.org/~luke/log/20070710-1129/on-forks-and-forking -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGxXn6/Pp1N6Uzh0URAgJ+AJ4/DM3329I1FbZni+3RVEcxyIopMQCfTPCh BHJ29mKSLb7MA39AJsJEfa0=nglm -----END PGP SIGNATURE-----
On Aug 16, 2007, at 3:46 PM, esquid2@gmail.com wrote:> 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?You''ve hit it exactly -- someone just has to step up and do it. -- Football is a mistake. It combines the two worst elements of American life. Violence and committee meetings. -- George F. Will --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Friday 17 August 2007, Luke Kanies wrote:> On Aug 16, 2007, at 3:46 PM, esquid2@gmail.com wrote: > > 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? > > You''ve hit it exactly -- someone just has to step up and do it.This discussion has prompted me to look a bit into it. After a bit discussion, this mockup of the manifest syntax is now my target:> $target = "/home/david/Work/puppet/puppet/david/test.conf" > > file { $target: checksum => md5 } > > define custom_syntax($ensure) { > param { "Conf{ ${name} } = ": > ensure => "''${value}'';", > target => $target, > } > } > > custom_syntax { > param1: ensure => value1; > param2: ensure => value2; > }With the intention of doing param as the actual native ruby type, which searches case and whitespace insensitively for a line in $target beginning with $name and forcing the line to be $name$ensure. This seems to be the minimally invasive, maximally flexible solution. For individual config files, this can be wrapped into a define as demonstrated with Custom_syntax. Now I just have to implement it :) Comments, Opinions? Regards, David - -- The primary freedom of open source is not the freedom from cost, but the free- dom to shape software to do what you want. This freedom is /never/ exercised without cost, but is available /at all/ only by accepting the very different costs associated with open source, costs not in money, but in time and effort. - -- http://www.schierer.org/~luke/log/20070710-1129/on-forks-and-forking -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGxf2h/Pp1N6Uzh0URAqEmAJ9mHUkvRi/QKE8Yv0Jvy8cS4sF8TgCeNO5S mqHAEyLd3uxyE3pLx15dz+A=Yp62 -----END PGP SIGNATURE-----
--On Friday, August 17, 2007 10:31:41 AM +1000 Matthew Palmer <mpalmer@hezmatt.org> wrote:> I''ve tried re-writing the ''replace_line'' define as a native type, and got > nowhere. (I''ve also tried writing Nagios-related types and an rsync file > transfer type, neither of them have gotten off the ground). I find that > the documentation for writing types and providers, while fine if you want > to rewrite an existing type, isn''t good enough to properly reason about > how to use the API in new and interesting ways.When was the last time you reviewed it? Because Luke updated it recently after I cried like a little girl trying to make heads or tails of it.
On Fri, Aug 17, 2007 at 03:39:42PM -0700, Digant C Kasundra wrote:> --On Friday, August 17, 2007 10:31:41 AM +1000 Matthew Palmer > <mpalmer@hezmatt.org> wrote: > > > I''ve tried re-writing the ''replace_line'' define as a native type, and got > > nowhere. (I''ve also tried writing Nagios-related types and an rsync file > > transfer type, neither of them have gotten off the ground). I find that > > the documentation for writing types and providers, while fine if you want > > to rewrite an existing type, isn''t good enough to properly reason about > > how to use the API in new and interesting ways. > > When was the last time you reviewed it? Because Luke updated it recently > after I cried like a little girl trying to make heads or tails of it.Less than a week ago. I was working from all of the "Puppet Internals", "Complete Resource Example", and "Creating Custom Types". No dice. - Matt