Puppet Function: deferlib::cmd

Defined in:
functions/cmd.pp
Function type:
Puppet Language

Summary

returns output of deferred shell command execution or options[else] if commmand exit code not 0 or output does not match options[match]

Overview

deferlib::cmd(Hash $options)Any

Examples:

ensure cron from file content on agent side

service { 'cron':
  ensure => deferlib::cmd({
    'command'     => 'cat /etc/cron_ensure',
    'match'       => '^(running|stopped)$',
    'else'        => 'running',
    'user'        => 'foo',
    'group'       => 'bar',
    'environment' => { 'myvar' => 'myvalue' },
  }),
}

Parameters:

  • options (Hash)

    options of shell execution

Options Hash (options):

  • 'command' (String)

    shell command to execute

  • 'match' (String)

    regexp to validate output of command

  • 'else' (Any)

    returned value if command exit code not 0

  • 'user' (Variant[String,Integer])

    The user to run the command as

  • 'group' (Variant[String,Integer])

    The group to run the command as

  • 'environment' (Hash)

    Hash of environment variable names / variable values

Returns:

  • (Any)

    output of command or options

Author:

  • Franck Jouvanceau



34
35
36
37
38
# File 'functions/cmd.pp', line 34

function deferlib::cmd (
  Hash $options,
) {
  Deferred('deferlib::cmd_', [$options])
}