Trace: Commands stanza

Commands stanza

Cfengine 3

Commands stanza

This page shows all the elements within a “commands:” stanza in Cfengine 3.

commands:
  "/path/to/command args"
    args    => "more args",
    contain => contain_body,
    module  => true/false;

args

This is simply a string of additional arguments.

commands:
  "/bin/echo one"
   args => "two three";

contain

This is a compound body with the following possible elements. Default values are bold.

ElementValuesDescription
chdirAny valid pathDirectory for setting current/base directory for the process.
chrootAny valid pathDirectory of root sandbox for process.
exec_groupAny valid group or ID (root)The group name or id under which to run the process.
exec_ownerAny valid name or ID (root)The user name or ID under which to run the process.
exec_timeout1-3600 sec.Cancel a command if not complete in specified seconds.
no_outputtrue / falseDiscard all output from the command (equivalent to piping standard output and error to /dev/null).
previewtrue / falsePreview command when running in dry-run mode (with -n).
umask0 77 22 27 72 077 022 027 072Set the umask value for the child process.
usesshelltrue / falseSet true to embed the command in a shell environment. A shell is necessary to combine commands with pipes.

Example

body contain example {
  chdir        => "/containment/directory",
  chroot       => "/private/path",
  exec_owner   => "mysql_user",
  exec_group   => "nogroup",
  exec_timeout => "30",
  no_output    => "true",
  preview      => "true",
  umask        => "077",
  usesshell    => "false";
  }

module

True/false setting (defaults to false).

Whether to expect the cfengine module protocol. If true the module protocol is supported for this script, i.e., it is treated as a user module. A plug-in module may be written in any language and can return any output, but:

  • lines which begin with a ‘+’ sign are treated as classes to be defined (like -D)
  • lines which begin with a ‘-’ sign are treated as classes to be undefined (like -N)
  • lines starting with ‘=’ are variables/macros to be defined

Any other lines of output are cited by cf-agent as being erroneous, so you should normally make your module completely silent.

commands:
   "/masterfiles/user_script"
     module => "true";

Here is an example module written in perl.

#!/usr/bin/perl
#
# module:myplugin
#
  # lots of computation....
if (special-condition) {
  print "+specialclass";
  }

Further documentation is here.