On 5/26/11 9:34 PM, Aleksey Tsalolikhin wrote: > Thanks for sharing, Sjoerd. How do you use this? > > I can imagine a use for appending a line if it is not already in a file, > but what is the scenario where you want to append a line if some > other regex is not in a file? > I'm using it in my yum policy at the moment. Yum needs to know about NFS mounted locations so that it won't touch files there.
To do that you add these locations to /etc/rpm/macros.nfs Like so: %_netsharedpath /home:/mnt/foo:/bar I add this line using the policy from the original mail. This line is then modified by some more policy (on some servers) and paths are added. Because the line is then changed, it would get added again if I didn't use some regex matching. You may wonder why I wouldn't just add specific lines to this config in specific cases, but I think this is a more elegant solution. --------- files: "/etc/rpm/macros.nfs" comment => "Yum can't handle NFS mounts, and needs to know about them.", classes => if_repaired("rpm_macros_fixed"), create => "true", edit_line => append_line_if_no_match(".*netsharedpath.*",'%_netsharedpath /foo:/bar'); ftp_servers|cf_policyhosts:: "/etc/rpm/macros.nfs" comment => "Add some more nfs mounts to existing line", classes => if_repaired("rpm_macros_fixed"), edit_line => append_subfield(" ",":","%_netsharedpath ","2","/var/baz"); www_servers:: "/etc/rpm/macros.nfs" comment => "Add some more nfs mounts to existing line", classes => if_repaired("rpm_macros_fixed"), edit_line => append_subfield(" ",":","%_netsharedpath ","2","/var/qux"); _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine