[augeas-devel] Path and increasing identifiers
David Lutterkort
lutter at redhat.com
Wed Dec 16 16:45:25 UTC 2009
On Wed, 2009-12-16 at 15:28 +0100, Tim Stoop wrote:
> 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?
For numbered nodes (like the ones underneath /files/etc/hosts) the
easiest is to just use numbers that start with a '0', since Augeas will
never use such numbers, i.e. 01, 02 etc. will always be unique. You can
therefore do something like the following in puppet
augeas { myhost:
changes =>
"set /files/etc/hosts/01/ipaddr 192.168.0.1
set /files/etc/hosts/01/canonical gateway.example.com
... ",
onlyif => "match /files/etc/hosts/*[ipaddr = '192.168.0.1'] size == 0"
}
The expressions 'last()' and 'last()+1' only have a meaning inside
predicates (the stuff in [ ... ]) in path expressions, and are generally
used when adding to a list of nodes that all have thesame name, like the
aliases for an entry in /etc/hosts. For example, to an alias to the
entry with IP 192.168.0.1 (assuming we know it exists), you would write
in augtool
augtool> set /files/etc/hosts/*[ipaddr='192.168.0.1']/alias[last()+1] myhost.example.com
David
More information about the augeas-devel
mailing list