--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengine+unsubscribe@googlegroups.com.
To post to this group, send email to help-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/help-cfengine.
For more options, visit https://groups.google.com/d/optout.
If I understand correctly, you have a list of managed files that should
exist in a directory. That directory potentially contains a bunch other
files that you don't want to exist. If this is the case, I think that
you can use difference()
to figure out which files should be absent.
Here is a small self contained example that shows how /tmp/example/
is
maintained so that only the list of wanted files exists.
bundle agent main { vars: # mkdir /tmp/example && cd /tmp/example && touch this directory contains many files but only some do we want to keep "files" slist => { "special", "files", "we", "want", "to", "exist" }; # Find all files that are not '.' and '..' "found" slist => lsdir("/tmp/example/", "[^.]{1,2}.*", "no"); # Figure out which files exist that are not in the list of files we explicitly want. "extras" slist => difference( found, files ); files: "/tmp/$(extras)" -> { "jira:1235" } delete => tidy, comment => "Only explictly managed files should exist"; "/tmp/$(files)" -> { "jira:1234" } create => "true", comment => "We need these files to exist or something dosn't work well"; }
If you really only wanted to purge the extras when a change was made, then you
could define a class based on the result of the promise to manage the files.
body file control { include => { "$(sys.libdir)/stdlib.cf" }; } bundle agent main { vars: # mkdir /tmp/example && cd /tmp/example && touch this directory contains many files but only some do we want to keep "files" slist => { "special", "files", "we", "want", "to", "exist" }; # Find all files that are not '.' and '..' "found" slist => lsdir("/tmp/example/", "[^.]{1,2}.*", "no"); # Figure out which files exist that are not in the list of files we explicitly want. "extras" slist => difference( found, files ); files: "/tmp/$(files)" -> { "jira:1234" } create => "true", classes => results("bundle", "file_$(files)"), comment => "We need these files to exist or something dosn't work well"; "/tmp/$(extras)" -> { "jira:1235" } if => classify("file_$(files)_repaired"), delete => tidy, comment => "Only explictly managed files should exist"; }
–
Nick Anderson
Doer of things, CFEngine