On 2009-May-19, at 4:09 PM, David Lutterkort wrote:

> Think of the subtree under /2 etc. as a record - in almost all cases,
> these records have some notion of primary key;

Which is why I wonder why /etc/inittab doesn't just use the 'id' field  
instead of assigning a number, or why /etc/hosts doesn't just use the  
IP address. But like I said, treating things as a numbered sequence is  
going to be unavoidable in some places, so my time is probably better  
spent figuring out how to handle it, rather than nitpicking this or  
that lens.

> Putting all the above together, you can write this as
>
>             # adds rh:06:wait:/etc/rc.shutdown
>             augeas { "shutdown":
>               require => File["shutdown"],
>               context => "/files/etc/inittab",
>               changes => [
>                 "set 01/id rh",
>                 "set 01/runlevels 06",
>                 "set 01/action wait",
>                 "set 01/process /etc/rc.shutdown",
>               ],
>               onlyif => "match *[id = 'rh'] size == 0",
>             }

If I don't care about order (which I probably shouldn't), this works  
well. Thanks. One minor correction: I had to remove whitespace inside  
the square brackets to get it to work, so it ended up being

     onlyif => "match *[id='rh'] size == 0",

> If you always want your entry to show up after the 'si' line, you  
> ned to
> do the explicit 'ins' as the first thing in your changes, something  
> like
> 'ins 01 after */[id = 'si']'

For the sake of discussion, let's say I was going to try an insert in  
a specific place. I haven't been able to get the path expression to  
work in that context. I have tried each of the following:

     "ins 0 after *[id='si']",
     "ins 0 after *[id=\"si\"]",
     "ins 0 after *[id=\'si\']",
     'ins 0 after *[id="si"]',
     'ins 0 after *[id=\'si\']',
     'ins 0 after *[id=\"si\"]',
     "ins 0 after \"*[id='si']\"",

And in every case, I get an error implying that it sees 'si' and the  
closing ] as two additional parameters, rather than as part of the  
expression.

     err: //was/Augeas[shutdown]: Failed to retrieve current state of  
resource: Error sending command 'ins 0 after *[id=' with params ["si",  
"]"]/Command 'ins 0 after *[id=' is not supported

The following version will go through without error, but it doesn't  
actually match anything so the new item gets inserted at the end of  
the file:

     "ins 0 after *[id=si]",

For what it's worth, this works fine in augtool:

     ins 0 after /files/etc/inittab/*[id='si']

Should I file a bug or am I doing something wrong here? I'm running  
RHEL 5.3 with Puppet 0.24.8 and Augeas 0.5.0 from EPEL.

>>     # boot systems to runlevel 3
>>     augeas { "runlevel":
>>       context => "/files",
>>       changes => [
>>         "set /etc/inittab/1/runlevels 3",
>>       ],
>>       onlyif => "get /etc/inittab/1/action == initdefault",
>>     }
>>
>> Again, this works, but what if initdefault was *not* item 1?
>
> Use "set /etc/inittab/*[action = 'initdefault']/runlevels 3" - for  
> that,
> you don't even need an onlyif. If runlevels is already 3, Augeas will
> notice that nothing has changed when the tree is saved, and won't  
> touch
> the file at all.

Great! That seems much cleaner. Unfortunately, I get the same type of  
errors as the above when trying to use it.

     err: //Augeas[runlevel]: Failed to retrieve current state of  
resource: Error sending command 'set /etc/inittab/*[action=' with  
params ["initdefault", "]/runlevels 3"]/Command 'set /etc/inittab/ 
*[action=' is not supported

>> On a related note, there doesn't seem to be a good way to add  
>> comments
>> to a particular spot to explain the changes you've made. This is true
>> even for the "straightforward" files mentioned above. Any advice?
>
> Most lenses now map comments as nodes labelled '#comment', and you can
> do something like the following to add a comment just before a given
> node:
>
>        ins #comment before /files/etc/hosts/*[ipaddr = '127.0.0.1']
>        set /files/etc/hosts/#comment[. = ''] "My new comment"
>
> though the 'set' is a bit of a kludge (it looks for comment nodes with
> an empty comment) - the Augeas path expressions clearly need a better
> way to refer to newly created nodes, or to refer to nodes by a more
> complicated criterion, i.e. so that you can say 'the #comment node  
> just
> before the one with an ipaddr child with value 127.0.0.1'.

Sure, there's room for improvement, but I think this trick will  
accomplish what I want as long as I can count on changes being  
processed in order. For instance, canonical_maps doesn't exist by  
default, so in order to put a comment before it, I need to set it first.

     augeas { "main.cf":
       require => Package["postfix"],
       context => "/files/etc/postfix/main.cf",
       changes => [
         "set canonical_maps ldap:/etc/postfix/addresses.ldap",
         "ins #comment before canonical_maps",
         "set #comment[.=''] 'refer to LDAP for e-mail address'",
       ],
       notify => Service["postfix"],
     }

Of course, the "#comment[.='']" expression throws errors too, so I  
can't use this until that's sorted out. :)

Lots of good info in this thread. Thanks everyone.

-- 
Rob McBroom
<http://www.skurfer.com/>


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to