Forum: Cfengine Help
Subject: Re: Wildcard in files stanza on copy
Author: zzamboni
Link to topic: https://cfengine.com/forum/read.php?3,17887,17981#msg-17981

Hi Kent,

I've spent some time trying to accomplish what you need without resorting to 
execresult() - I have not been successful. The following _almost_ works, except 
that (a) the destination file must exist already, and (b) in the end, cfengine 
wants to copy the file to /tmp/testdest and not to the found path (there should 
be some option that you want to copy to ${this.promiser}):

bundle agent copyfiles
{
files:
  "/tmp/testdest"
    file_select => nodedir,
    depth_search => recurse("inf"),
#    transformer => "/bin/echo found ${this.promiser}";
    copy_from => mycopy("file");
}

body file_select nodedir
{
  path_name => { "/tmp/testdest/node.*/dir2/file" };
  file_result => "path_name";
}

body copy_from mycopy(from)
{
  source => "/tmp/testrepo/${from}";
  compare => "digest";
}

body depth_search recurse(d)
{
  depth => "$(d)";
}


In the end, the only way I could find was to use execresult to find the 
directory name. For me, the following code worked fine (I tested this in Win7 
under cygwin), without any need to postprocess the output from ls.

bundle agent copyfiles
{
vars:
  # Find the directory
  "nodedir" string => execresult("/bin/ls /tmp/testdest | /bin/grep ^node", 
"useshell");

files:
  "/tmp/testdest/${nodedir}/dir2/file"
    copy_from => mycopy("file");
}

body copy_from mycopy(from)
{
  source => "/tmp/testrepo/${from}";
  compare => "digest";
}

I don't think it's so tragic to use execresult to obtain extra information 
about the precise state of the system, although it would be nice if cfengine 
had a way to assign into a variable the list of files that match a regex.

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to