Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Puppet 3 Cookbook

You're reading from   Puppet 3 Cookbook An essential book if you have responsibility for servers. Real-world examples and code will give you Puppet expertise, allowing more control over servers, cloud computing, and desktops. A time-saving, career-enhancing tutorial

Arrow left icon
Product type Paperback
Published in Aug 2013
Publisher Packt
ISBN-13 9781782169765
Length 274 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
John Arundel John Arundel
Author Profile Icon John Arundel
John Arundel
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Puppet 3 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Puppet Infrastructure 2. Puppet Language and Style FREE CHAPTER 3. Writing Better Manifests 4. Working with Files and Packages 5. Users and Virtual Resources 6. Applications 7. Servers and Cloud Infrastructure 8. External Tools and the Puppet Ecosystem 9. Monitoring, Reporting, and Troubleshooting 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 
      git@github.com: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 
      "john@bitfieldconsulting.com"
    ubuntu@cookbook:~/puppet$ git commit -m "Importing"
    [master a063a5b] Importing
    Committer: John Arundel <john@bitfieldconsulting.com>
    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 git@github.com: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.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime