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    # puppet 2.6 or greater
    $ ralsh package puppet              # puppet 2.5 or less

    package { 'puppet':
      ensure => '2.6.4-0.5.fc14'
    }

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

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 (or ralsh if you're on an older version) you can do just that.

When you run with a provider and a resource on your local machine puppet resource 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.

See also

  • puppet resource –help
  • man ralsh