Book Description
Puppet is a configuration management system that automates all your IT configurations, giving you control of what you do to each node, when you do it, and how you do it.
Puppet Cookbook Third Edition takes the reader from a basic knowledge of Puppet to a complete and expert understanding of Puppet’s latest and most advanced features. Updated with the latest advancements and best practices, it gives you a clear view on how to "connect the dots" and expands your knowledge to successfully use and extend Puppet.
This book delves into various aspects of writing good Puppet code, which includes using Puppet community style, checking your manifests with puppet-lint, and learning community best practices, with an emphasis on real-world implementation.
Read an Extract from the book
Generating manifests with the Puppet resource command
If you have a server that is already configured as it needs to be, or nearly so, you can capture that configuration as a Puppet manifest. The Puppet resource command generates Puppet manifests from the existing configuration of a system. For example, you can have puppet resource generate a manifest that creates all the users found on the system. This is very useful to take a snapshot of a working system and get its configuration quickly into Puppet.
How to do it...
Here are some examples of using puppet resource to get data from a running system:
- To generate the manifest for a particular user, run the following command:
[root@cookbook ~]# puppet resource user thomas user { 'thomas': ensure => 'present', comment => 'thomas Admin User', gid => '1001', groups => ['bin', 'wheel'], home => '/home/thomas', password => '!!', password_max_age => '99999', password_min_age => '0', shell => '/bin/bash', uid => '1001', } - For a particular service, run the following command:
[root@cookbook ~]# puppet resource service sshd service { 'sshd': ensure => 'running', enable => 'true', } - For a package, run the following command:
[root@cookbook ~]# puppet resource package kernel package { 'kernel': ensure => '2.6.32-431.23.3.el6', }
There's more...
You can use puppet resource to examine each of the resource types available in Puppet. In the preceding examples, we generated a manifest for a specific instance of the resource type, but you can also use puppet resource to dump all instances of the resource:
[root@cookbook ~]# puppet resource service
service { 'abrt-ccpp':
ensure => 'running',
enable => 'true',
}
service { 'abrt-oops':
ensure => 'running',
enable => 'true',
}
service { 'abrtd':
ensure => 'running',
enable => 'true',
}
service { 'acpid':
ensure => 'running',
enable => 'true',
}
service { 'atd':
ensure => 'running',
enable => 'true',
}
service { 'auditd':
ensure => 'running',
enable => 'true',
}This will output the state of each service on the system; this is because each service is an enumerable resource. When you try the same command with a resource that is not enumerable, you get an error message:
[root@cookbook ~]# puppet resource file
Error: Could not run: Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etcAsking Puppet to describe each file on the system will not work; that's something best left to an audit tool such as tripwire (a system designed to look for changes on every file on the system, http://www.tripwire.com)


