Pro Puppet (22 page)

Read Pro Puppet Online

Authors: Jeffrey McCune James Turnbull

BOOK: Pro Puppet
11.14Mb size Format: txt, pdf, ePub
developer:~modules/ $ git rebase -i master

This command will open, in your default text editor, a list of commits to the topic branch since it diverged from the master development branch. In order to clean up the commit history, the developer replaces “pick” with “squash” in the line listing his commit to add the missing curly brace. This will effectively combine this commit with the commit above it, where the curly brace should have been present in the first place.

pick 0c164f6 Added manual change warning to postfix config
pick 7acf23d Updated config.pp to use $module_name
squash 6b9f2b5 Fixup missing closing curly brace
# Rebase fa9812f..6b9f2b5 onto fa9812f
#
# Commands:
#  pick = use commit
#  edit = use commit, but stop for amending
#  squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.

Once the developer makes this change, he saves the file and quits the editor.
git
rewrites history for him, giving him the option to change the commit message of the freshly cleaned commit:

".git/COMMIT_EDITMSG" 17L, 524C written
Created commit e4e27c7: Updated config.pp to use $module_name
 1 files changed, 2 insertions(+), 2 deletions(-)
Successfully rebased and updated refs/heads/developer/postfix

The developer is now ready to publish his topic branch to the rest of his colleagues and to the puppet master system itself, in order to check out the topic branch in the
/etc/puppet/environments/development/modules
repository.

developer:~/modules $ git push origin developer/postfix:developer/postfix
Counting objects: 21, done.
Compressing objects: 100% (14/14), done.
Writing objects: 100% (15/15), 1.79 KiB, done.
Total 15 (delta 3), reused 0 (delta 0)
To [email protected]:git/modules.git
 * [new branch]      developer/postfix -> developer/postfix

Next, he logs into the puppet master system as the user
puppet
, fetches his topic branch from the central repository, and then checks out his topic branch in the development environment. This process will switch the current development environment away from whatever branch it was previously on. This could potentially interfere with the work of the operator. If this becomes a common problem, it is possible to set up more environments to ensure each contributor has their own location to test their changes without interfering with others.

puppet:~ $ cd /etc/puppet/environments/development/modules
ppuppet:modules $ git fetch origin
remote: Counting objects: 21, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 15 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (15/15), done.
From [email protected]:git/modules
 * [new branch]      developer/postfix -> origin/developer/postfix
puppet:modules $ git checkout -b developer/postfix origin/developer/postfix
Branch developer/postfix set up to track remote branch refs/remotes/origin/developer/postfix.
Switched to a new branch "developer/postfix"

The developer’s topic branch has now been checked out in the location the Puppet master is using for the development environment.

Testing the Puppet Agent Against the Postfix Configuration File

You can run the Puppet agent against the development environment, as we have previously and as shown in
Listing 3-4
, to verify your changes.

Listing 3-4.
Testing the Puppet

agentroot:~ # puppet agent --test --noop --environment development
info: Caching catalog for scd.puppetlabs.vm
info: Applying configuration version '1289764649'
--- /etc/ssh/sshd_config        2010-11-14 12:11:28.000000000 -0800
+++ /tmp/puppet-file.25961.0    2010-11-14 12:11:40.000000000 -0800
@@ -3,5 +3,4 @@
 SyslogFacility AUTHPRIV
 PermitRootLogin no
 PasswordAuthentication yes
-AllowGroups wheel adm
 UsePAM yes
notice: /Stage[main]/Ssh::Config/File[/etc/ssh/sshd_config]/content: is {md5}da5
4f2cdc309faf6d813a080783a31f6, should be {md5}9d4c3fba3434a46528b41a49b70b60e4 (
noop)
info: /Stage[main]/Ssh::Config/File[/etc/ssh/sshd_config]: Scheduling refresh of
 Service[sshd]
notice: /Stage[main]/Ssh::Service/Service[sshd]: Would have triggered 'refresh'
from 1 events
--- /etc/postfix/master.cf      2010-11-14 11:54:37.000000000 -0800
+++ /tmp/puppet-file.22317.0    2010-11-14 11:58:15.000000000 -0800
@@ -1,3 +1,5 @@
+# This file managed by puppet.  Manual changes will be reverted.
+#
 #
 # Postfix master process configuration file.  For details on the format
 # of the file, see the master(5) manual page (command: "man 5 master").
notice: /Stage[main]/Postfix::Config/File[/etc/postfix/master.cf]/content: is
 {md5}3b4d069fa7e4eb6570743261990a0d97, should be {md5}710171facd4980c2802a354ee4cb4a4e (noop)
info: /Stage[main]/Postfix::Config/File[/etc/postfix/master.cf]: Scheduling refresh of
 Service[postfix] notice: /Stage[main]/Postfix::Service/Service[postfix]: Would have
 triggered 'refresh' from 1 events
notice: Finished catalog run in 0.61 seconds

The Puppet agent run against the development environment shows us that Puppet will update the Postfix configuration file and notify the Postfix service as a result. Notice how the changes we’ve made to this system by trying out the
operator/ssh
branch will now be reverted. This is because the developer created his branch from the
master
branch and the operator has not yet merged her
operator/ssh
branch back into master, therefore her changes are not present.

At this point, both the changes of the operator and the developer have been tried in using the development environment. It’s now time to merge both change lists into a testing branch and make them both available in the testing Puppet environment.

Merging Changes into a Testing Environment

Unlike the development Puppet environment, where anything goes and people may perform a checkout on their branches to quickly try out their changes and topic branches, the testing environment should change less frequently. The process of merging topic branches from the master development branch into a testing branch periodically, once every two weeks for example, has worked well for many projects and companies. In this section, we work through the process of merging change lists into the testing branch with the goal of ultimately promoting the testing branch to a production release.

Creating the Testing Branch

First, our system administrator will create a new branch, called “testing,” based on the current master branch we started with. When starting out with Puppet, this testing branch and the process of merging change lists should be set early on in order to provide a good reference point. It also provides and staging area that’s not quite as risky as the development environment, and does not require a release process like the production environment does.

The system administrator creates the new testing branch in a manner similar to how the operator and developer created their topic branches. This should be done in the personal repository the system administrator has in her home directory:

sysadmin:~modules/ $ git checkout testing master
Switched to a new branch "testing"

Note
There is no technical difference between a topic branch and a testing branch the system administrator creates for the testing environment. The team is simply using a convention of treating the testing branch as a long-lived branch to merge change lists into. Similarly, the master branch is the branch where current development happens.

Merging the Changes into the Development Branch

Before checking out the testing branch on the Puppet master, the system administrator decides to merge the change lists from the operator and the developer into the main development branch. This keeps the main development branch in sync with the testing branch and allows the system administrator to advance the master development branch with additional changes without affecting the testing environment, which will only be updated on the Puppet master periodically.

sysadmin:~modules/ $ git fetch origin
From [email protected]:git/modules
 * [new branch]      developer/postfix -> origin/developer/postfix
 * [new branch]      operator/ssh -> origin/operator/ssh
sysadmin:~modules/ $ git merge --no-ff origin/developer/postfix
Merge made by recursive.
 postfix/files/master.cf     |    4 +++-
 postfix/manifests/config.pp |    4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)
sysadmin:~modules/ $ git merge --no-ff origin/operator/ssh
Merge made by recursive.
 ssh/files/sshd_config |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

  
Tip
It is a good idea to perform a
git fetch origin
to see if there are any changes in the central repository prior to merging topic branches. If there are, then performing
git merge origin/master
while on the master branch will bring those changes into the local repository.

Other books

Wild by Leigh, Adriane
The Shepherd's Voice by Robin Lee Hatcher
Uprising by Therrien, Jessica
Kelpie (Come Love a Fey) by Draper, Kaye
Disciple of the Wind by Steve Bein
Unbound Pursuit by Lindsay McKenna
Just F*ck Me! by Eve Kingsley