On Fri, 2009-06-12 at 04:46 -0700, Hui wrote: > Hi guys, > > I was enlightened by the 'puppet+augeas modprobe.conf' post (thanks!) > and was going to put inittab under puppet/augeas management. > > My goal is to add this one line for spawning a console on the serial > port if it doesn't exist: > co:12345:respawn:/sbin/agetty ttyS0 19200 vt100 > > However the task proved to be more tricky than I first imaged. There > were two thing I was stuck on. Firstly inittab tree in augeas starts > with number instead of arrays, and I had to work around to append with > ins and last().
Assuming you're happy with appending that line to the end of the file, you shouldn't need to do anything fancy .. just a bunch of set's should be fine. > Secondly the match in onlyif didn't seem to like > spaces, so I was unsure how I can match the sequence exactly. That is a bug that's been addressed in the current master branch (ticket #2141) > I came up with the following: > augeas { "inittab": > context => "/files/etc/inittab", > changes => [ "set 100/id 'co'", > "set 100/runlevels 12345", > "set 100/action respawn", > "set 100/process \"/sbin/agetty ttyS0 19200 vt100\"", > ], > onlyif => "match */id[.='co'] size == 0'", > #onlyif => "match */process[.='/sbin/agetty ttyS0 19200 vt100'] > size == 0", > } > > So for my first problem, I used an arbitary large number (100) so it's > outside the existing line ranges - not robust and could inadvertently > overwrite something else. A much better way to make sure numbered nodes are truly unique is to use labels that start with a '0' - you're guaranteed that they will never appear in a tree that was just read from file; so you'd say "set 01/id 'co'" etc. > But for the matching, the first onlyif > works but the commented out one would error with That can actually be also written as "match *[id='co'] size == 0" > err: //Augeas[inittab]: Failed to retrieve current state of resource: > Error sending command 'match' with params ["vt100']", "size", "==", > "0"]/unknown error - Matching path expression '/files/etc/inittab/*/ > process[.='/sbin/agetty' failed That's another manifestation of bug #2141. > I would really want to match on the serial console port (ttyS0) in > case it's named under a different id on an existing host. This would really require that Augeas path expressions grow a way to match regexps or at least substrings, so that you could say onlyif => "match *[process =~ @^/sbin/agetty tt...@] size == 0" or some such. David --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en -~----------~----~----~----~------~----~------~--~---