Setting cfengine3 class based on command output

Posted by gnomie on Server Fault See other posts from Server Fault or by gnomie
Published on 2012-10-10T09:20:44Z Indexed on 2012/10/10 9:40 UTC
Read the original article Hit count: 259

Filed under:

This question is very similar to How can I use the output of a command in cfengine3 but the answer does not apply in my case I believe.

I want to update a git repository via "git pull" and based on whether that lead to changes trigger some follow up action.

Simplified, if there was something like "match output and set class" via some body if_output_matches I would want to use something like this:

bundle agent updateRepo {

commands:
  "/usr/bin/git pull"
    contain => setuidgiddir_sh("$(globals.user)","$(globals.group)","$(target)"),
    classes => if_output_matches("Already up-to-date.","no_update");

reports:
  no_update::
    "nothing updated";
}

body contain setuidgiddir_sh(owner,group,folder) {
  exec_owner => "$(owner)";
  exec_group => "$(group)";
  useshell => "true";
  chdir => "$(folder)";

}

So, is it possible to use the output of a - possibly expensive command - and base some decision on that?

The execresult function is no good choice for me as a) the pull may become expensive at times (not recommended following the cfengine3 reference) and b) does not allow to specify user, group, working dir - which is important in my case. The repository is in user space and not owned by root.

© Server Fault or respective owner

Related posts about cfengine