Book Image

Puppet 3 Cookbook - Second Edition

By : John Arundel
Book Image

Puppet 3 Cookbook - Second Edition

By: John Arundel

Overview of this book

A revolution is happening in web operations. Configuration management tools can build servers in seconds, and automate your entire network. Tools like Puppet are essential to taking full advantage of the power of cloud computing, and building reliable, scalable, secure, high-performance systems. More and more systems administration and IT jobs require some knowledge of configuration management, and specifically Puppet."Puppet 3 Cookbook" takes you beyond the basics to explore the full power of Puppet, showing you in detail how to tackle a variety of real-world problems and applications. At every step it shows you exactly what commands you need to type, and includes full code samples for every recipe.The book takes the reader from a basic knowledge of Puppet to a complete and expert understanding of Puppet's latest and most advanced features, community best practices, writing great manifests, scaling and performance, and extending Puppet by adding your own providers and resources. It starts with guidance on how to set up and expand your Puppet infrastructure, then progresses through detailed information on the language and features, external tools, reporting, monitoring, and troubleshooting, and concludes with many specific recipes for managing popular applications.The book includes real examples from production systems and techniques that are in use in some of the world's largest Puppet installations, including a distributed Puppet architecture based on the Git version control system. You'll be introduced to powerful tools that work with Puppet such as Hiera. The book also explains managing Ruby applications and MySQL databases, building web servers, load balancers, high-availability systems with Heartbeat, and many other state-of-the-art techniques
Table of Contents (16 chapters)
Puppet 3 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Managing your manifests with Git


It's a great idea to put your Puppet manifests in a version control system such as Git or Subversion (I recommend Git) and give all Puppet-managed machines a checkout from your repository. This gives you several advantages:

  • You can undo changes and revert to any previous version of your manifest

  • You can experiment with new features using a branch

  • If several people need to make changes to the manifests, they can make them independently, in their own working copies, and then merge their changes later

  • You can use the git log feature to see what was changed, and when (and by whom)

Getting ready...

In this section we'll import your existing manifest files into Git. If you have created a puppet directory in the previous section, use that, otherwise use your existing manifest directory.

I'm going to use the popular GitHub service as my Git server. You don't have to do this, it's easy to run your own Git server but it does simplify things. If you already use Git and have a suitable server, feel free to use that instead.

Note

Note that GitHub currently only offers free repository hosting for public repositories (that is, everyone will be able to see and read your Puppet manifests). This isn't a good idea if your manifest contains secret data such as passwords. It's fine for playing and experimenting with the recipes in this book, but for production use, consider a private GitHub repo instead.

Here's what you need to do to prepare for importing your manifest:

  1. First, you'll need Git installed on your machine:

    ubuntu@cookbook:~/puppet$ sudo apt-get install git
    
  2. Next, you'll need a GitHub account (free for open-source projects, or you'll need to pay a small fee to create private repositories) and a repository. Follow the instructions at github.com to create and initialize your repository (from now on, just "repo" for short). Make sure you tick the box that says, Initialize this repository with a README.

  3. Authorize your SSH key for read/write access to the repo (see the GitHub site for instructions on how to do this).

How to do it...

You're now ready to add your existing manifests to the Git repo. We're going to clone the repo, and then move your manifest files into it, as follows:

  1. First, move your puppet directory to a different name:

    mv puppet puppet.import
    
  2. Clone the repo onto your machine into a directory named puppet (use your own repo URL, as shown on GitHub):

    ubuntu@cookbook:~$ git clone 
      [email protected]:bitfield/cookbook.git puppet
    Cloning into 'puppet'...
    remote: Counting objects: 3, done.
    remote: Total 3 (delta 0), reused 0 (delta 0)
    Receiving objects: 100% (3/3), done.
    
  3. Move everything from puppet.import to puppet:

    ubuntu@cookbook:~$ mv puppet.import/* puppet/
    
  4. Add and commit the new files to the repo, setting your Git identity details if necessary:

    ubuntu@cookbook:~$ cd puppet
    ubuntu@cookbook:~/puppet$ git status
    # On branch master
    # Untracked files:
    #   (use "git add <file>..." to include in what will be
      committed)
    #
    #       manifests/
    nothing added to commit but untracked files present (use "git
      add" to track)
    ubuntu@cookbook:~/puppet$ git add manifests/
    ubuntu@cookbook:~/puppet$ git config --global user.name "John
      Arundel"
    ubuntu@cookbook:~/puppet$ git config --global user.email 
      "[email protected]"
    ubuntu@cookbook:~/puppet$ git commit -m "Importing"
    [master a063a5b] Importing
    Committer: John Arundel <[email protected]>
    2 files changed, 6 insertions(+)
    create mode 100644 manifests/nodes.pp
    create mode 100644 manifests/site.pp
    
  5. Finally, push your changes back to GitHub:

    ubuntu@cookbook:~/puppet$ git push -u origin master
    Counting objects: 6, done.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (5/5), 457 bytes, done.
    Total 5 (delta 0), reused 0 (delta 0)
    To [email protected]:bitfield/cookbook.git
       6d6aa51..a063a5b  master -> master
    

How it works...

Git tracks changes to files, and stores a complete history of all changes. The history of the repo is made up of commits. A commit represents the state of the repo at a particular point in time, which you create with the git commit command and annotate with a message.

You've added your Puppet manifest files to the repo and created your first commit. This updates the history of the repo, but only in your local working copy. To synchronize the changes with GitHub's copy, the git push command pushes all changes made since the last sync.

There's more...

Now that you have a central Git repo for your Puppet manifests, you can check out multiple copies of it in different places and work on them, before committing your changes. For example, if you're working in a team, each member can have her own local copy of the repo and synchronize changes with the others via GitHub.

Now that you've taken control of your manifests with Git, you can use it as a simple, scalable way to distribute manifest files to lots of machines. We'll see how to do this in the next section.