Automating application deployment using puppet in eucalyptus/aws cloud.

 

 

 

In this example a user can pass userdata parameter which would decide the role of the emi/ami that would be launched, and based on the role applications would be deployed by the 

puppet master.

 

Prerequisites:

 A working puppet master server

an ami/emi with puppet client installed.

 

 

Steps:

 

On the ami/emi template update the rc.local as following:

TMP_FILE=”/tmp/user-data-$$”

 

curl –retry 3 –retry-delay 10 -o $TMP_FILE http://10.101.1.118:8773/latest/user-data

if [ -s $TMP_FILE ]; then

echo “Downloaded user data in $TMP_FILE”

if [ “`head -c 2 $TMP_FILE`” = “#!” ]; then

chmod a+x $TMP_FILE

echo “User data is a script: executing it”

sh $TMP_FILE

fi

ROLE=`cat $TMP_FILE | grep role | cut -d= -f2 | col -b`

cat > /usr/lib/ruby/site_ruby/1.8/facter/bentest.rb  <<EOF

Facter.add(:role) do

  setcode do

    role = ‘$ROLE’

  end

end

EOF

PUPPET=`cat $TMP_FILE | grep puppet | cut -d= -f2`

echo “$PUPPET puppet” >> /etc/hosts;

fi

 

 

What this does is creates a custom fact in the vm called as ‘role’ and assigns a value to it, this fact would be read by the manifests in the puppet master to decide what recipes should be pushed to the node.

it also makes an entry of the puppet master on the client node.(This is optional as you can define a hostname in the emi template and make sure the dns points it to right puppet server).

 

On the puppet master:

The first thing that the puppet master needs to do is identify the node and pass appropriate configurations, for this as we mentioned above the puppet master would look at the facter ‘role’ and decide the configuration to be sent.

 

sample on how to accomplish that:

 

site.pp

=====

 

/etc/puppet/site.pp

#Has all node configuration

import “nodes.pp”

import  “modules.pp”

# The filebucket option allows for file backups to the server

filebucket { main: server => ‘puppet’ }

 

# Set global defaults – including backing up all files to the main filebucket and adds a global path

File { backup => main }

Exec { path => “/usr/bin:/usr/sbin/:/bin:/sbin” }

 

/etc/puppet/manifests/nodes.pp

======================

 

node default{

include vmnodes::classifiers

}

 

module for vmode calssifers

=========================

 

/etc/puppet/modules/vmnodes/manifests/init.pp

import “classifiers.pp”

 

====Here it decides based on facter what configuration needs to be pushed.=============

 

/etc/puppet/modules/vmnodes/manifests/classifiers.pp

class vmnodes::classifiers{

 

case $role {

“dbserver” : {

include mysql

}

}

case $role {

“appserver” : {

include httpd

}

}

}

 

/etc/puppet/manifests/modules.pp

import vmnodes

 

Advertisements