Book Image

Puppet 3: Beginner's Guide

By : John Arundel
Book Image

Puppet 3: Beginner's Guide

By: John Arundel

Overview of this book

<p>Everyone's talking about Puppet, the open-source DevOps technology that lets you automate your server setups and manage websites, databases, and desktops. Puppet can build new servers in seconds, keep your systems constantly up to date, and automate daily maintenance tasks. <br /><br />"Puppet 3 Beginner's Guide" gets you up and running with Puppet straight away, with complete real world examples. Each chapter builds your skills, adding new Puppet features, always with a practical focus. You'll learn everything you need to manage your whole infrastructure with Puppet.<br /><br />"Puppet 3 Beginner’s Guide" takes you from complete beginner to confident Puppet user, through a series of clear, simple examples, with full explanations at every stage.</p> <p>Through a series of worked examples introducing Puppet to a fictional web company, you'll learn how to manage every aspect of your server setup. Switching to Puppet needn't be a big, long-term project; this book will show you how to start by bringing one small part of your systems under Puppet control and, little by little, building to the point where Puppet is managing your whole infrastructure.</p> <p>Presented in an easy-to-read guide to learning Puppet from scratch, this book explains simply and clearly all you need to know to use this essential IT power tool, all the time applying these solutions to real-world scenarios.</p>
Table of Contents (17 chapters)
Puppet 3 Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

If you work with computer systems, then you know how time-consuming it can be to install and configure software, to do administration tasks such as backups and user management, and to keep the machines up to date with security patches and new releases. Maybe you've already come up with some written procedures, shell scripts, and other ways to document your work and make it more automated and reliable.

Perhaps you've read about how Puppet can help with this, but aren't sure how to get started. The online documentation is great for reference, but doesn't really explain the whole thing from scratch. Many of the books and tutorials available spend a lot of time explaining how to set up your Puppet server and infrastructure before ever getting to the point where you can use Puppet to actually do something.

In my work as an infrastructure consultant I do a good deal of Puppet training, mostly for absolute beginners, and I've found that the most effective and fun way to do this is to get into some real work right away. In the first five minutes, I have people making changes to their systems using Puppet. If there was a fire alarm and we had to terminate the class after that first five minutes, they would still go away knowing something useful that could help them in their jobs.

I've taken the same approach in this book. Without going into lots of theory or background detail, I'll show you how to do useful things with Puppet right away: install packages and config files, create users, set up scheduled jobs, and so on. Every exercise deals with something real and practical that you're likely to need in your work, and you'll see the complete Puppet code to make it happen, along with step-by-step instructions for what to type and what output you'll see.

After each exercise, I'll explain in detail what each line of code does and how it works, so that you can adapt it to your own purposes, and feel confident that you understand everything that's happened. By the end of the book, you will have all the skills you need to do real, useful, everyday work with Puppet.

So let's get started.

What this book covers

Chapter 1, Introduction to Puppet, explains the problem of configuration management and why traditional manual approaches to them don't scale. It shows how Puppet deals with these problems efficiently, and introduces the basic architecture of Puppet.

Chapter 2, First Steps with Puppet, guides you through installing Puppet for the first time, creating a simple manifest, and applying it to a machine. You'll see how to use the Puppet language to describe and modify resources, such as a text file.

Chapter 3, Packages, Files, and Services, shows you how to use these key resource types, and how they work together. We'll work through a complete and useful example based on the Nginx web server.

Chapter 4, Managing Puppet with Git, describes a simple and powerful way to connect machines together using Puppet, and to distribute your manifests and work on them collaboratively using the version control system Git.

Chapter 5, Managing Users, outlines some good practices for user administration and shows how to use Puppet to implement them. You'll also see how to control access using SSH and manage user privileges using sudo.

Chapter 6, Tasks and Templates, covers more key aspects of automation: scheduling tasks, and building configuration files from dynamic data using Puppet's template mechanism.

Chapter 7, Definitions and Classes, builds on previous chapters by showing you how to organize Puppet code into reusable modules and objects. We'll see how to create definitions and classes, and how to pass parameters to them.

Chapter 8, Expressions and Logic, delves into the Puppet language and shows how to control flow using conditional statements and logical expressions, and how to build arithmetic and string expressions. It also covers operators, arrays, and hashes.

Chapter 9, Reporting and Troubleshooting, looks at the practical side of working with Puppet: how to diagnose and solve common problems, debugging Puppet's operations, and understanding Puppet error messages.

Chapter 10, Moving on Up, shows you how to make your Puppet code more elegant, more readable, and more maintainable. It offers some links and suggestions for further reading, and outlines a series of practical projects that will help you deliver measurable business value using Puppet.

What you need for this book

You'll need a computer system (preferably, but not essentially, Ubuntu Linux-based) and access to the Internet. You won't need to be a UNIX expert or an experienced sysadmin; I'll assume you can log in, run commands, and edit files, but otherwise I'll explain everything you need as we go.

Who this book is for

This book is aimed at system administrators, developers, and others who need to do system administration, who have grasped the basics of working with the command line, editing files, and so on, but want to learn how to use Puppet to get more done, and make their lives easier.

Conventions

In this book, you will find several headings appearing frequently.

To give clear instructions on how to complete a procedure or task, we use:

Time for action – heading

  1. Action 1

  2. Action 2

  3. Action 3

Instructions often need some extra explanation to make sense, so they are followed with:

What just happened?

This heading explains the working of tasks or instructions that you have just completed.

You will also find some other learning aids in the book, including:

Pop quiz – heading

These are short multiple-choice questions intended to help you test your own understanding.

Have a go hero – heading

These practical challenges give you ideas for experimenting with what you have learned.

You will also find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "To have Puppet read a manifest file and apply it to the server, use the puppet apply command."

A block of code is set as follows:

file { '/tmp/hello':
  content => "Hello, world\n",

}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

file { '/tmp/hello':
  content => "Hello, world\n",
}

Any command-line input or output is written as follows:

ubuntu@demo:~$ puppet apply site.pp 
Notice: /Stage[main]//Node[demo]/File[/tmp/hello]/ensure: defined content as '{md5}bc6e6f16b8a077ef5fbc8d59d0b931b9'
Notice: Finished catalog run in 0.05 seconds

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "On the Select Destination Location screen, click on Next to accept the default destination."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address, or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.