Pulling Strings With Puppet - James Turnbull [50]
Resources
The following links will take you to Puppet documentation related to external nodes and Puppet scalability:
• Using external nodes in Puppet:
• LDAP nodes in Puppet:
• Using Mongrel with Puppet:
• Using Mongrel with Pound:
• Using Mongrel with nginx:
• Puppet scalability documentation:
CHAPTER 7
Extending Puppet
Among the most powerful features of both Puppet and Facter are their flexibility and extensibility. In addition to the existing resource types and facts, you can quickly and easily add custom types and facts specific to your environment or to meet a particular need. In this chapter, we're going to examine how to add your own custom facts to Facter, have Puppet automatically distribute those facts, and then see how to make use of them. I'm also going to demonstrate how to create a simple resource type (and associated provider) for Puppet and how to integrate that new resource type into your Puppet installation. This chapter, however, is just an introduction to extending Puppet. If you want to learn more, there is extensive documentation available on the Puppet Wiki and on the Puppet Developer mailing list.
When developing custom types and facts, it is important to remember that Puppet and Facter are open source tools developed both by Reductive Labs and a wide community of contributors. Sharing custom facts and resource types helps everyone in the community and means you can also get input from the community on your work. Extending Puppet or Facter is also an excellent way to give back to that community. You can share your custom types and facts via the Puppet mailing list, on the Puppet Wiki, logging a Trac ticket, or setting up your own source repository for Puppet or Facter code.
Tip - We aren't going to discuss it in this chapter, but you can also extend Puppet by creating your own functions. You can see more details of this at http://reductivelabs.com/trac/puppet/wiki/WritingYourOwnFunctions.
Extending Facter
Adding your own custom facts to Puppet is a very simple process that requires only a limited understanding of Ruby. To add a new fact, we add a snippet of Ruby code to our Puppet master. Puppet then distributes our custom facts to all our clients using a function called factsync. Each client that connects to the master gets all the facts available synchronized down to it.
Configuring Puppet for Custom Facts
We start with telling Puppet to turn on fact synchronization using the factsync configuration option. We then specify where Puppet will find our facts using the factpath configuration option. You can see both these options in Listing 7-1.
In Listing 7-1, we've turned on fact synchronize and specified the path, in our case $vardir/facts, which on most installations would default to /var/puppet/facts, where our facts will be located on our master. You can specify multiple paths by separating each with colons.
By default, with factsync enabled, Puppet clients look for facts at puppet: //$server/facts much like file serving.
Tip -► Remember, $server is a fact with the hostname of our Puppet master that is only available on the master.
Each fact is treated as a file resource and served out by the built-in Puppet file server. As factsync uses the built-in file server, you can use any valid file source to deliver your facts. To override the default file source for facts, use the factsource configuration option.
Tip - File serving is described in Chapter 4.
Facts are downloaded to our clients and stored in a local directory, usually also $vardir/facts on the client, but this can be overridden using the factdest configuration option (though obviously only one destination path can be configured).
After restarting the master daemon, Puppet will now be ready to deliver facts to your client nodes. These facts are then available to your configuration as variables in the same way as the facts provided by Facter.
Tip - There are other configuration options you can use to tweak your fact configuration that you can read about athttp://reductivelabs.com/trac/puppet/wiki/ConfigurationReference.