A collection of task oriented solutions in Puppet

 

You want some resource examples

Challenge

You'd like to see some example resources in the puppet configuration format

Solution

$ puppet resource package puppet

package { 'puppet':
  ensure => '4.2.1-5.fc25',
}

# an example host file entry resource
$ puppet resource host localhost.localdomain
host { 'localhost.localdomain':
  ensure       => 'present',
  host_aliases => ['localhost', 'puppet'],
  ip           => '127.0.0.1',
  target       => '/etc/hosts',
}
# an example user resource
$ puppet resource user daemon
user { 'daemon':
  ensure           => 'present',
  comment          => 'daemon',
  gid              => '2',
  home             => '/sbin',
  password         => '*',
  password_max_age => '99999',
  password_min_age => '0',
  shell            => '/sbin/nologin',
  uid              => '2',
}

Explanation

When you are starting out in puppet the first few resources of each type you use can be awkward to write. There are never enough examples and sometimes you just want to see what something looks like on your local system through the eyes of puppet. Thanks to puppet resource you can do just that.

When you run the command with a specific provider and resource name, for example puppet resource package strace on your local machine, puppet will try to load them in the way it does during a normal puppet run. If this succeeds it will present the resource in the same format as you'd use in your manifest. While some examples, such as the user above, provide more options than you'd normally specify, having the ability to introspect and crib from your existing setup can help the learning process and speed up those first few manifests.

Not all types are able to work under the puppet resource subcommand. To see a list of all the available ones you can run puppet resource --types.

See also

  • puppet resource --help