A collection of task oriented solutions in Puppet

 

You'd like nicer names for your exec resources

Challenge

You're using the command in the exec resource name and it's ugly, unwieldy and awkward to use from other resources.

Solution

class nicer_exec_names {

  # exec with the command as the name
  exec { '/bin/mkdir -p /tmp/needed/directory': }

  package { 'needed':
    ensure  => 'installed',
    # awkward, long require
    require => Exec['/bin/mkdir -p /tmp/needed/directory'],
  }


  # nicer, human friendly naming
  exec { 'create_needed_directory':
    command => '/bin/mkdir -p /tmp/needed/directory',
  }

  package { 'needed':
    ensure  => 'installed',
    # easier to read require
    require => Exec['create_needed_directory'],
  }

}

Explanation

Older manifests, as well as newer ones written by less experienced puppet users, often use the actual command as the name of the exec. While this works, and can even be used in other parameters such as require, it is a little unwieldy and leads to a certain unneeded leaking of information to other resources.

It's much nicer to use a human readable explanation of what the command is for as the execs name and then put the actual command in the "command" property.