I'm trying to use Augeas to declare/ensure that a particular mount point exists in fstab. If it already is there, make sure it has these $settings, otherwise create a new line that does.
But I haven't been able to get augeas to do that. I can get it to modify an existing line and I can get it add a new line. But not both, as in (pseudocode):
if (line_exists) {
check_and_modify_line()
} else {
create_new_line()
}
To check_and_modify_line()
, this works:
set /files/etc/fstab/*[file="/mnt/ISO"]/file "/mnt/ISO"
set /files/etc/fstab/*[file="/mnt/ISO"]/spec "nas:/ISO/iso"
set /files/etc/fstab/*[file="/mnt/ISO"]/vfstype "nfs"
set /files/etc/fstab/*[file="/mnt/ISO"]/opt "intr"
set /files/etc/fstab/*[file="/mnt/ISO"]/dump "0"
set /files/etc/fstab/*[file="/mnt/ISO"]/passno "0"
To create_new_line()
, this works:
set /files/etc/fstab/01/spec "nas:/ISO/iso"
set /files/etc/fstab/01/file "/mnt/ISO"
set /files/etc/fstab/01/vfstype "nfs"
set /files/etc/fstab/01/opt[1] "intr"
set /files/etc/fstab/01/dump "0"
set /files/etc/fstab/01/passno "0"
But the secret sauce that combines the above two sections into a single one eludes me. And I thought that Augeas was supposed to be declarative/idempotent, so it surprises me quite a lot that I can't tell Augeas: "Make sure this line exists".
There also don't seem to be any if/then/else style blocks, because then I could:
if match /files/etc/fstab/*[file="/mnt/ISO"]
defnode isonode /files/etc/fstab/*[file="/mnt/ISO"]
else
defnode isonode /files/etc/fstab/01
set $isnode/file "/mnt/ISO"
set $isnode/bla "bla-bla"
Is there a way to do this all in a single bunch of "set" operations or a single .aug file, so I can run a single:
sudo augtool < mountpoint.aug
Sure I could use a couple of augeas puppet resources with mutually exclusive onlyif
-s, or a wrapper e.g. in bash or perl with some combination of grep, sed etc. but then I might as well stick to using that completely and not Augeas...
By the way, is there more comprehensive official documentation for using Augeas than the tiny tour? The entire documentation seems to be dedicated to new lens developers, not for the presumably more numberous lens users.