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:
First, you'll need Git installed on your machine:
ubuntu@cookbook:~/puppet$ sudo apt-get install git
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.
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:
First, move your
puppet
directory to a different name:mv puppet puppet.import
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.
Move everything from
puppet.import
topuppet
:ubuntu@cookbook:~$ mv puppet.import/* puppet/
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
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.