[augeas-devel] Path and increasing identifiers

David Lutterkort lutter at redhat.com
Wed Dec 16 16:48:48 UTC 2009


On Wed, 2009-12-16 at 15:39 +0100, Raphaël Pinson wrote:
> On Wed, Dec 16, 2009 at 3:28 PM, Tim Stoop <tim.stoop at gmail.com> wrote:
> > Hi all,
> >
> > I'm trying to knit some of our puppet recipes together with Augeas,
> > because I think the Augeas way of working is much nicer than sourcing
> > files. However, I'm running into one thing I can't seem to solve: Take
> > the /etc/hosts file, every entry has a unique identifier (like
> > /files/etc/hosts/1/), how do I determine which one is the highest, so
> > I can automatically do something like last()+1 for a new IP address?
> >
> 
> last()+1 is exactly it :-)
> e.g. augtool print '/files/etc/hosts/*[last()]'
> 
> 
> And your can use last()+1 in your insert command.

The trick with adding by using last()+1 only works if you know the label
of the new node, like for adding an alias:

        set /files/etc/hosts/1/alias[last()+1] myhost.example.com
        
but not when you don't know the label, i.e.

        set /files/etc/hosts/*[last()+1]/ipaddr 192.168.0.1
        
will fail, since Augeas has no clue what to call the tree node it has to
create for the *[last()+1] bit in the path.

David





More information about the augeas-devel mailing list