Skip to content

Instantly share code, notes, and snippets.

@nickanderson
Created May 11, 2016 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickanderson/83054c7cd9c81c5f73cd5c0036e133bc to your computer and use it in GitHub Desktop.
Save nickanderson/83054c7cd9c81c5f73cd5c0036e133bc to your computer and use it in GitHub Desktop.
body agent control
{
    # Files matching these patterns will only be *copied* to by cfengine once
    # per agent run.
      files_single_copy => { "/tmp/dest/.*" };
}

bundle agent main
{
  vars:

    # This is the order of preference. First successful copy wins
      "tree_order" slist => { "most_specific", "less_specific", "least_specific" };

    # These are the files I want to copy
      "files" slist => { "/etc/motd", "/etc/issue" };

  files:
      "/tmp/dest/$(files)"
        create => "true", # necessary in order to create subdirectories
        copy_from => single_copy_hierarchy( "/tmp/files_single_copy", @(tree_order), @(files) );

  methods:
      "two";
}

bundle agent two
{
  vars:

      # This is the order of preference. First successful copy wins
      "tree_order" slist => { "most_specific", "less_specific", "least_specific" };

      # These are the files I want to copy
      "files" slist => { "/etc/motd", "/etc/issue" };

  files:
      "/tmp/dest/$(files)"
        create => "true", # necessary in order to create subdirectories
        copy_from => single_copy_hierarchy( "/tmp/files_single_copy", @(tree_order), @(files) );

}
body copy_from single_copy_hierarchy(base_tree, subtree_order, files)
# @param base_tree (string) The fully qualified path to the root of your single copy hierarchy
# @param subtree_order (list) The order in which to traverse subtrees
# @param files (list)
{

      source => "$(base_tree)/$(copy_order)/$(files)";
      compare => "digest";
}

files_single_copy

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