Created
March 15, 2013 22:14
-
-
Save baptr/5173516 to your computer and use it in GitHub Desktop.
Class based copy source
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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! |
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
$ grep . /tmp/copytest/*/myfile
/tmp/copytest/classA/myfile:from classA!
/tmp/copytest/classB/myfile:from classB!