Forum: CFEngine Help Subject: Re: copy_from: would like priority list of sources, then silent fail Author: zzamboni Link to topic: https://cfengine.com/forum/read.php?3,25584,25588#msg-25588
David, I think hierarchical copy could do what you want: see http://blog.zzamboni.org/hierarchical-copying-with-cfengine3 and http://blog.zzamboni.org/implementing-single-copy-nirvana-in-cfengine3 (this is also described in my book). Note that the variable part of the filename (through which CFEngine will loop, and copy the first available file) is presented in these examples as a file suffix, but it doesn't have to be - it could be any arbitrary part of the filename to copy, including the directory. CFEngine will loop over all the combinations, and copy the first one it finds. If none are found, then it will copy nothing. So you could have something like this: body agent control { files_single_copy => { ".*" }; } bundle agent copy files { vars: "locations" slist => { "/main/location", "/secondary/location", "/tertiary/location" }; "files" slist => { "/etc/foo1", "/var/foo2", "/usr/foo3" }; files: "$(files)" copy_from => mycopy("$(locations)$(files)"); } This will try to copy /etc/foo1 from /main/location/etc/foo1, /secondary/location/etc/foo1, /tertiary/location/etc/foo1 in sequence. If none of those exist, then nothing will be copied. Similarly for the other files. Hope this helps, _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine