[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [augeas-devel] Path and increasing identifiers



On Wed, 2009-12-16 at 18:10 +0100, Raphaël Pinson wrote:
> On Wed, Dec 16, 2009 at 5:48 PM, David Lutterkort <lutter redhat com> wrote:
> > 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 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.
> >
> 
> Ah, thanks for the clarification David, that makes perfect sense :-)

Since this seems to come up quite a bit, I added a page to the Wiki
describing insertion and appending:
http://augeas.net/page/Adding_nodes_to_the_tree

David




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]