Skip to content

Instantly share code, notes, and snippets.

@baptr
Created March 15, 2013 22:14
Show Gist options
  • Save baptr/5173516 to your computer and use it in GitHub Desktop.
Save baptr/5173516 to your computer and use it in GitHub Desktop.
Class based copy source
$ cat copytest.cf
body common control {
bundlesequence => { "test" };
}
body copy_from local_cp(from) {
source => "$(from)";
compare => "digest";
}
bundle agent test {
vars:
"classlist" slist => { "classA", "classB" };
classes:
"classA" not => "classB";
files:
"/tmp/myfile"
copy_from => local_cp("/tmp/copytest/$(classlist)/myfile"),
ifvarclass => "$(classlist)";
}
$ /var/cfengine/bin/cf-agent -KIf ./copytest.cf -DclassA; cat /tmp/myfile
Running full policy integrity checks
-> Updated /tmp/myfile from source /tmp/copytest/classA/myfile on localhost
from classA!
$ /var/cfengine/bin/cf-agent -KIf ./copytest.cf -DclassA; cat /tmp/myfile
Running full policy integrity checks
from classA!
$ /var/cfengine/bin/cf-agent -KIf ./copytest.cf -DclassB; cat /tmp/myfile
Running full policy integrity checks
-> Updated /tmp/myfile from source /tmp/copytest/classB/myfile on localhost
from classB!
@baptr
Copy link
Author

baptr commented Mar 15, 2013

$ grep . /tmp/copytest/*/myfile
/tmp/copytest/classA/myfile:from classA!
/tmp/copytest/classB/myfile:from classB!

@baptr
Copy link
Author

baptr commented Mar 15, 2013

One thing to watch out for with this method, if multiple classes are defined, you'll see extra churn, and the class that iterates last from the list would win (assuming no locks):
$ /var/cfengine/bin/cf-agent -KIf ./copytest.cf -DclassA,classB; cat /tmp/myfile
Running full policy integrity checks
-> Updated /tmp/myfile from source /tmp/copytest/classA/myfile on localhost
-> Updated /tmp/myfile from source /tmp/copytest/classB/myfile on localhost
from classB!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment