Book Image

Puppet 4 Essentials, Second Edition - Second Edition

By : Felix Frank, Martin Alfke
Book Image

Puppet 4 Essentials, Second Edition - Second Edition

By: Felix Frank, Martin Alfke

Overview of this book

Puppet is a configuration management tool that allows you to automate all your IT configurations, giving you control over what you do to each Puppet Agent in a network, and when and how you do it. In this age of digital delivery and ubiquitous Internet presence, it's becoming increasingly important to implement scalable and portable solutions, not only in terms of software, but also the systems that run it. The free Ruby-based tool Puppet has established itself as the most successful solution to manage any IT infrastructure. Ranging from local development environments through complex data center setups to scalable cloud implementations, Puppet allows you to handle them all with a unified approach. Puppet 4 Essentials, Second Edition gets you started rapidly and intuitively as you’ll put Puppet’s tools to work right away. It will also highlight the changes associated with performance improvements as well as the new language features in Puppet 4. We’ll start with a quick introduction to Puppet to get you managing your IT systems quickly. You will then learn about the Puppet Agent that comes with an all-in-one (AIO) package and can run on multiple systems. Next, we’ll show you the Puppet Server for high-performance communication and passenger packages. As you progress through the book, the innovative structure and approach of Puppet will be explained with powerful use cases. The difficulties that are inherent to a complex and powerful tool will no longer be a problem for you as you discover Puppet's fascinating intricacies. By the end of the book, you will not only know how to use Puppet, but also its companion tools Facter and Hiera, and will be able to leverage the flexibility and expressive power implemented by their tool chain.
Table of Contents (15 chapters)
Puppet 4 Essentials Second Edition
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Introducing classes and defined types


Puppet's equivalents to methods or functions are twofold: there are classes on one hand and defined types (also just referred to as defines) on the other.

Note

You will find that the function analogy is a bit weak for classes, but fits defined types quite well.

They are similar at first glance, in that they both hold a chunk of reusable manifest code. There are big differences in the way each is used though. Let's take a look at classes first.

Defining and declaring classes

A Puppet class can be considered to be a container for resources. It is defined once and selected by all nodes that need to make use of the prepared functionality. Each class represents a well-known subset of a system's configuration.

For example, a classic use case is a class that installs the Apache web server and applies some basic settings. This class will look like the following:

class apache {
  package { 'apache2':
    ensure => 'installed',
  }
  file { '/etc/apache2/apache2.conf...