Skip to content

Automating a Puppet Agent Installation

March 19, 2012

Puppet is a very popular configuration management system. It allows users to deploy new infrastructure in a cloud or traditional enterprise environment quickly and efficiently. When an organization utilizes a configuration management system, it allows IT and DevOps groups to effectively replicate environments on the fly with little to no interaction with the new instance or system.

The basic building block for using puppet in the cloud is through the puppet agent. The puppet agent has two main actions:

  • Applying a manifest to the systems it’s running on
  • Working with a puppet master to coordinate a new deployment

In this post we will be focusing on the first aspect of the puppet agent mentioned above by using it in a standalone configuration.

What will our script do in this post?

  • Update the instance
  • Setup the hostname
  • Install the puppet agent
  • Create a manifest for the puppet agent to work with that will install vim and Apache2
  • Apply the puppet manifest to the instance

All of these actions will be accomplished with a single command, euca-run-instances. With a simple deployment like this, we reduce complexity for new instance deployment and will give more power to cloud users. This has the side effect of making IT’s talk list much shorter, gives teams a quicker turn around time for new systems, and allows for new systems that are spun up to look exactly the same which reduces the possibility of errors.

For this post I’m going to use the Eucalyptus Community Cloud and a Debian Squeeze image (emi-00781826). Below is the script that will do what was outlined above. Copy it from here (or GitHub – Puppet Agent Install) and save it to your local machine for use.

#!/usr/bin/env bash

FULL_HOSTNAME="myhost.mydomain"
SHORT_HOST=`echo ${FULL_HOSTNAME} | cut -d'.' -f1`
APTITUDE=`which aptitude`
APT_KEY=`which apt-key`

###########
# Setup the hostname for the system. Puppet really relies on 
# the hostname so this must be done.
###########
hostname ${FULL_HOSTNAME}

sed -i -e "s/\(localhost.localdomain\)/${SHORT_HOST} ${FULL_HOSTNAME} \1/" /etc/hosts

###########
# Need to add in the aptitude workarounds for instances.
# * First disable dialog boxes for dpkg
# * Add the PPA for ec2-consistent-snapshot or else the update will hang.
###########
export DEBIAN_FRONTEND=noninteractive
export DEBIAN_PRIORITY=critical

${APT_KEY} adv --keyserver keyserver.ubuntu.com --recv-keys BE09C571

###########
# Update the instance and install the puppet agent
###########
${APTITUDE} update
${APTITUDE} -y safe-upgrade
${APTITUDE} -y install puppet

PUPPET=`which puppet`

##########
# Setup the puppet manifest in /root/my_manifest
##########
cat >>/root/my_manifest.pp <<EOF
package {
    'apache2': ensure => installed
}

service {
    'apache2':
        ensure => true,
        enable => true,
        require => Package['apache2']
}

package {
    'vim': ensure => installed
}
EOF

############
# Apply the puppet manifest
############
$PUPPET apply /root/my_manifest.pp

############
# End of script cleanup.
############
export DEBIAN_FRONTEND=dialog
export DEBIAN_PRIORITY=high

This script very pretty basic. First we take care of some basics like setting the hostname on the instance and we update the instance to the latest software available. We then install the puppet agent onto the system and find where the new binary is located. Next we create a file containing our puppet manifest that we wish to install and finally we apply the manifest to the instance.

To use the script with a new instance use the -f flag for euca-run-instances like so:

euca-run-instances -k <my_key> -t <instance_size> -f <path_to_script> emi-00781826

This is just a basic example of how you can utilize puppet inside of your Eucalyptus or EC2 compliant cloud with a metadata service.

(Looking to try this out with CentOS? There’s a script for it on GitHut – Puppet Agent Install. Try it out on the ECC with EMI emi-709D1676.)

Edit: I’ve added a CentOS 6 script for this as well now. Check it out at the GitHub repo above!

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 53 other followers

%d bloggers like this: