Online Book Reader

Home Category

Pulling Strings With Puppet - James Turnbull [32]

By Root 389 0

Or, we can do so when Puppet is executed:

The command on the previous line would execute Puppet and only implement configuration that was tagged devel. Multiple tags can be specified, separated by commas.

Using Templating

The last function, template, is also one of the most useful and allows you to make use of Ruby ERB templates. This allows us to create template files, like configuration files for example, that can be populated with configuration data from Puppet.

Tip - With ERB, Ruby code is added to plain text to generate files. You can read about ERB templates in more detail at http: //www. ruby-doc. org/stdlib/libdoc/erb/rdoc/.

In Listing 3-30, we can see a simple template.

In Listing 3-30, we've created a class called resoly and specified two variables, $searchpath and $nameservers (which is an array), and a file resource that configures the /etc/resolv.conf file. We've specified the content attribute and called the template function in it. We've specified a template file called resolv-template.erb.

Tip - You can specify multiple templates by separating each with commas.

Template files need to be located on the master server, and by default, if you don't specify a full path, Puppet searches for them in the location specified in the templatedir configuration value in your configuration file. This option is usually set to /var/puppet/templates.

Inside a template you can reference any variable that is in the current scope; in Listing 3-30 you could use the $searchpath and $nameservers variables in the specified template. Now let's have a look at the template file.

You can see we've specified an ERB template that will receive the $searchpath and $nameservers variables. We've also specified a little piece of Ruby code that will iterate through the $nameservers array. Iteration can be used in conjunction with definitions to create multiple files of a particular type, for example, creating Apache virtual hosts. If we configure Listing 3-30 on a node, the end result would look like the following:

This is a very simple example of using the template function, and we'll see others, including using templates in definitions to create configuration and similar files in Chapter 4.

Resources

We've looked at how the Puppet language works in this chapter, and there are useful resources and documentation online that can also help you learn more.

You can also log tickets and bug reports at Puppet's trac site by registering at http://reductivelabs.com/trac/puppet/register.

Web

• Puppet language tutorial:

• Puppet type reference (including metaparameters):

• Puppet function reference:

• Puppet style guide:

CHAPTER 4

Using Puppet

In Chapter 3, we talked about the syntax of the Puppet language and how to use that syntax to express configuration. In this chapter, we're going to look at Puppet's capabilities and how to make use of that language to articulate actual configurations on your nodes. We're going to do this by showing you how to configure a real environment using Puppet. Using the examples in this chapter, you will make use of the syntax you learned in Chapter 3.

All of these examples represent one way of implementing Puppet in your environment. The examples are designed to give you an idea of how a production Puppet implementation could work. Some of the examples represent some best practice guidelines, but others are simply ideas about how you might go about using Puppet to articulate your configuration.

We'll also look at how to manage and store your Puppet configuration including using a revision control system, file serving, and modules. By the end of this chapter, you should have a strong understanding of what Puppet can do to manage your nodes and the best way to articulate, store, and administer that configuration.

Note - All the configuration examples in this chapter are available as a source code download from the Apress site.

Our Example Environment

We're going to configure an example environment with Puppet. You can see a visual representation of this environment

Return Main Page Previous Page Next Page

®Online Book Reader