[augeas-devel] augtool: exit non-zero on match failure and idempotent inserts

Clemens Wehrmann clemitu at googlemail.com
Fri Jan 15 09:01:05 UTC 2010


Hello,

I have a couple of question from my first turn with augeas:

1. The build instructions at [1] didn't work for me on Ubuntu 9.10:
  a. in a addition to readline, flex and bison (input fails on byacc) are 
required when building from git, but neither documented in the instructions, 
nor the configure script.
  b. The gnulib-tool --lgpl=2 check in the bootstrap script fails on langinfo 
(see [2])

2. I would expect to be able to use "augtool match" as a more syntax-aware 
"grep -q" replacement, but this is hampered because augtool does not allow 
detection of match failure via the exit status like grep, one must awkwardly 
parse the "  (no matches)" output designed more for human consumption.

3. I would expect saving of a node without a lens to fail or yield an error, 
but it doesn't: [3].

4. Using augtool from scripts really requires a significant wrapper to handle 
the frequent use case of idempotently adding a line:
  * add a node (subtree) if it doesn't exist
  * do nothing if it exists with the same values as set
  * if an exiting node exists with deviating values complain and abort or, if 
requested, set the values to the desired state.
  * handle errors reliably

Puppet addresses this to some extent, by providing the "onlyif" clause, but 
there are some servers without access to puppet and distributing a shell 
wrapper is also awkward.  Would the maintainers entertain a patch to add such 
functionality to augtool? Would a global guard-type option as in puppet or an 
extension to the set/ins syntax be preferable?   Something like [4] is the 
functionality I'm looking for. 

Many thanks for a very useful library.
--clemens

[1]
http://augeas.net/developers.html

[2]
clemens at shaun:~/devel/tmp/augeas$ ./autogen.sh 
I am going to run ./configure with --enable-warnings - if you 
wish to pass any extra arguments to it, please specify them on 
the ./autogen.sh command line.
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `build/aux'.
libtoolize: copying file `build/aux/ltmain.sh'
libtoolize: putting macros in `gnulib/m4'.
libtoolize: copying file `gnulib/m4/libtool.m4'
libtoolize: copying file `gnulib/m4/ltoptions.m4'
libtoolize: copying file `gnulib/m4/ltsugar.m4'
libtoolize: copying file `gnulib/m4/ltversion.m4'
libtoolize: copying file `gnulib/m4/lt~obsolete.m4'
libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.ac and
libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
./bootstrap: getting gnulib files...
Initialized empty Git repository in 
/home/clemens/devel/tmp/augeas/.gnulib/.git/
remote: Counting objects: 18645, done.
remote: Compressing objects: 100% (10560/10560), done.
remote: Total 18645 (delta 14331), reused 10260 (delta 8063)
Receiving objects: 100% (18645/18645), 8.37 MiB | 254 KiB/s, done.
Resolving deltas: 100% (14331/14331), done.
.gnulib/gnulib-tool: *** incompatible license on modules:
                 langinfo                                          LGPL
                 nl_langinfo                                       LGPL
.gnulib/gnulib-tool: *** Stop.

[3]
clemens at shaun:~/devel/augeas$ augtool <<EOF; echo result: $?
set /files/etc/typo_in_filename/foo "foo"
save
EOF

result: 0

[4]
# Find a node by "primary key" or make a new one by iterating over 0[1-9]
[0-9]* until one is not found.
defnode n /files/etc/fstab/*_or_new[spec="foo"]
# Set node values if they do not exist or are already set correctly.  Bail if 
they conflict.
set_but_fail_if_value_differs $n/spec "foo"
set_but_fail_if_value_differs $n/file "bar"
set_but_fail_if_value_differs $n/vfstype "ext4"
# reset node values regardless of their previous value
rm $n/opt
set $n/opt[last()+1] "opt1"
set $n/opt[last()+1] "opt2"
set $n/dump "0"
set $n/passno "0"
save




More information about the augeas-devel mailing list