Forum: Cfengine Help
Subject: Re: Parsing fstab
Author: Beto
Link to topic: https://cfengine.com/forum/read.php?3,20565,20683#msg-20683
Well the problem turned out to not be related to the readstringlist or grep
functions but with faulty iteration over variables. I was able to work around
it by removing some promises from the reports: section (see bug report 00479)
Thanks to neilwatson and michoski for their help and comments. michoski, I
realize that your method of handling fstab configuration is better and
ultimately the way I want to do it but my systems are spread across multiple
organizational boundaries and it will take some time to get there.
Meanwhile, for anyone that might be interested, here is my final version of the
bundle to ensure NFS file systems are mounted:
#########################################################
#
# Check nfs mounts
bundle agent mount_nfs
{
vars:
# Read /etc/fstab into the list "fstab".
"fstab" slist => readstringlist(
"/etc/fstab",
"#.*",
"\n",
"32",
"2048"
);
# grep the nfs entries in fstab.
"nfs" slist => grep(".*\snfs\s.*","fstab");
methods:
"any $(nfs)"
usebundle => mount("$(nfs)");
}
bundle agent mount(fs)
{
classes:
# Extract NFS server name, files system and mount point into the
# backreferences nfs_mount[1-3].
"isnfs" expression =>
regextract("([^\s]+)\:([^\s]+)\s+([^\s]+)\s+.*","$(fs)","nfs_mount");
storage:
linux.isnfs::
"$(nfs_mount[3])"
mount => nfs_m("$(nfs_mount[1])","$(nfs_mount[2])");
reports:
isnfs.nfsReport::
# The nfsclass report can be used for testing with the following command:
# cf-agent -KIb mount_nfs -DnfsReport -f ./promises.cf
"--------- Mounts to check ---------";
"Server: $(nfs_mount[1]) | FileSystem: $(nfs_mount[2]) | MountPoint:
$(nfs_mount[3])";
}
#########################################################
#
# Bodies
#
body mount nfs_m(server,source)
{
mount_type => "nfs";
mount_source => "$(source)";
mount_server => "$(server)";
edit_fstab => "false";
}
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine