Part 6 - Using purpose specific Types

In the preceding part of this guide we only copied files around, but if you really want to manage all aspects of your environment you're going to need more, you need to add users, add packages, create directories, set up package repositories and yes even create host entries.

Puppet has a rich set of types to manage a lot of different aspects of unix servers, these are all documented on the Type Reference and cover a wide range of aspects of unix machines including execution of commands and several others, have a scan through the list of contents of the Type Reference to get an overview.

We will use the host type to improve our hosts class.

Using the host type

Have a read of the documentation for the host type, it covers the basics of what you'd expect:

Lets see how to add the puppet host entry and one for the current host using the host type:

class host {
   host{"puppet":
      ip    => 192.168.1.5,
   }

   host{"${fqdn}":
      ip    => $ipaddress,
      alias => $hostname,
   } 
}

This effectively replace the template that we had previously, except we are not using the if to restrict it to the devco.net domain for simplicity. Note how the alias parameter is optional.

Run puppetd --test and confirm that the results is as expected.

Advantages

There are many advantages to this approach, for example existing /etc/hosts entries that aren't specifically defined here will be left alone, the keen observers between you should have noticed that the localhost entry stayed in tact in the hosts file even though we did not specifically create it.

If you imagine for a moment a more complex architecture where you needed an ldap hosts entry only when you install ldap authentication on a node, the ldap class could take care of installing and configuring ldap authentication and then also add the hosts entry for ldap at that time. This concept of granular management extends through all areas of Puppet.

You would not have such granular control by simply copying whole files around.

Removing hosts entries

If you read through the host type reference document you may have wondered how to remove a host entry? The host type has an ensure parameter, if we wanted to make sure that no hosts have a bastion host entry we could do this, add it to our hosts class:

   host {"bastion":
      ensure => absent,
   }

If you now run the client you should see no change at first, add a host entry for a host called bastion then run puppet, it will remove the host entry for you.

Conclusion

You've now seen how to use other types for doing specific tasks, you should spend some time exploring other types, try some of these ideas on your own:

Once you start exploring these types the full potential of puppet will become clear very quickly.

Check back soon for part 7

Puppet/GettingStarted/6 (last edited 2008-08-29 21:48:41 by RIPienaar)