POST
Hierarchical copying with cfengine3
I recently posted a snippet to perform hierarchical copying in cfengine3. As I was attempting to integrate this mechanism into my copy of cfengine's COPBL, I realized that no additional functions or body components are needed. Thanks to cfengine3's list expansion, all you need to do is include in the existing copy promise the list containing the desired list of suffixes to try. For example:
files: | |
suse_9:: | |
"${sys.workdir}/bin" | |
perms => usystem("0700"), | |
copy_from => mycopy("${repository}/bin/suse_9"), | |
depth_search => urecurse("1"); |
Becomes:
vars: | |
"suffixes" slist => { "${sys.flavour}" }; | |
files: | |
"${sys.workdir}/bin" | |
perms => usystem("0700"), | |
copy_from => mycopy("${repository}/bin.${suffixes}"), | |
depth_search => urecurse("1"); |
While this looks at first sight even longer than the original (and of course, in this case you could just specify ${sys.flavour} directly in the copy_from statement), it is much more flexible. Instead of defining different sections for each class that you want to handle (e.g. suse_9, redhat_5, etc.), the same code is able to copy the corresponding binary directory for any operating system, you just have to put the corresponding bin.* directory in your repository.
Furthermore, without modifying the code, you can provide different binaries for specific hosts, for different domains, or for any other classification you want to impose. Just modify the @suffixes variable, ordering them from the most specific to the most general one:"suffixes" slist => { "${sys.fqhost}", "${sys.domain}", "${sys.flavour}", | |
"${sys.ostype}", "${myarbitraryvariable}", "" }; |
You can do this without any additional functions, just adding ${suffixes} in the appropriate place in the copy arguments. The advantage of using a different function as in my previous post (or even better, modifying your existing copy function), is that you can add hierarchical copying without having to modify all copy promises in your policy.
- Tags:
- cfengine
- hierarchicalcopy
- tips
- Related:
- Limited Time Promotion! 50% off "Learning CFEngine 3"
- New Release of "Learning CFEngine 3"
- CFEngine talks at PICC'12 conference
- Learning CFEngine 3 has been released
- CFEngine posts moving to cf-learn.info
- cf-cmd: A command-line tool for running CFEngine snippets
- New website for "Learning CFEngine 3"
- "Learning CFEngine 3" Early Release now available -use AUTHD to get 40-50% off
- "Security in the Third Wave of IT Engineering"
- What's New in CFEngine 3: Making System Administration Even More Powerful - O'Reilly Radar
- "Introduction to CFEngine 3 Nova" webinar
- New job, new book
- Installing cfengine on Mac OS X
- Editing sshd configuration files with cfengine3
- Cfengine3 lexer for Pygments
- Storing CFEngine configuration in CVS
- The State of Open Source System Automation
- Editing whitespace-separated config files with cfengine
- cfengine Community Open Promise Body Library on GitHub
- Detecting NICs that match certain IP addresses
- Implementing "single-copy nirvana" in cfengine3
- Installing cfengine on Windows 7 under cygwin