deferlib

Reference

Table of Contents

Functions

Functions

deferlib::cmd

Type: Puppet Language

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

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' },
  }),
}

deferlib::cmd(Hash $options)

The deferlib::cmd function.

Returns: Any output of command or options[else]

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' },
  }),
}
options

Data type: Hash

options of shell execution

Options:

deferlib::if_cmd

Type: Puppet Language

returns value if deferred shell command execution exit code 0 else returns options[else]

Examples

if command /bin/ismaintenance ensure cron service stopped else ensure running
service { 'cron':
  ensure => deferlib::if_cmd('/bin/ismaintenance', 'stopped', {
    'else'        => 'running',
    'user'        => 'foo',
    'group'       => 'bar',
    'environment' => { 'myvar' => 'myvalue' },
  }),
}

deferlib::if_cmd(String $cmd, Any $value, Optional[Hash] $options = {})

The deferlib::if_cmd function.

Returns: Any value or options[else]

Examples
if command /bin/ismaintenance ensure cron service stopped else ensure running
service { 'cron':
  ensure => deferlib::if_cmd('/bin/ismaintenance', 'stopped', {
    'else'        => 'running',
    'user'        => 'foo',
    'group'       => 'bar',
    'environment' => { 'myvar' => 'myvalue' },
  }),
}
cmd

Data type: String

shell code to execute

value

Data type: Any

value to return if command exit code is 0

options

Data type: Optional[Hash]

shell execution options

Options:

deferlib::if_file

Type: Puppet Language

returns value if file exists else returns default

Examples

ensure service cron is stopped if file /etc/maintenance exists, else ensure running
service { 'cron':
  ensure => deferlib::if_file('/etc/maintenance', 'stopped', 'running')
}

deferlib::if_file(String $file, Any $value, Any $default = undef)

The deferlib::if_file function.

Returns: Any

Examples
ensure service cron is stopped if file /etc/maintenance exists, else ensure running
service { 'cron':
  ensure => deferlib::if_file('/etc/maintenance', 'stopped', 'running')
}
file

Data type: String

path to file to check existence

value

Data type: Any

value to return if file exists

default

Data type: Any

value to return if file does not exist (default: [])

deferlib::unless_cmd

Type: Puppet Language

returns value if deferred shell command execution exit code not 0 else returns options[else]

Examples

ensure cron service running unless command /bin/ismaintenance returns 0
service { 'cron':
  ensure => deferlib::unless_cmd('/bin/ismaintenance', 'running'),
}

deferlib::unless_cmd(String $cmd, Any $value, Optional[Hash] $options = {})

The deferlib::unless_cmd function.

Returns: Any value or options[else]

Examples
ensure cron service running unless command /bin/ismaintenance returns 0
service { 'cron':
  ensure => deferlib::unless_cmd('/bin/ismaintenance', 'running'),
}
cmd

Data type: String

shell code to execute

value

Data type: Any

value to return if command exit code is not 0

options

Data type: Optional[Hash]

shell execution options

Options:

deferlib::unless_file

Type: Puppet Language

returns value if file does not exist else returns default

Examples

ensure service cron is running unless file /etc/maintenance exists
service { 'cron':
  ensure => deferlib::unless_file('/etc/maintenance', 'running')
}

deferlib::unless_file(String $file, Any $value, Any $default = undef)

The deferlib::unless_file function.

Returns: Any

Examples
ensure service cron is running unless file /etc/maintenance exists
service { 'cron':
  ensure => deferlib::unless_file('/etc/maintenance', 'running')
}
file

Data type: String

path to file to check existence

value

Data type: Any

value to return if file does not exist

default

Data type: Any

value to return if file exists (default: [])