Yearly Archives: 2008

Configure Ubuntu and CentOS Webserver using Puppet

As I’m playing with the EC2 Puppet setup, here’s my simple web server in CentOS and Ubuntu puppet recipe. (need to edit more the Ubuntu installed packages ex. add php_mysql etc)

Tested in CentOS 5.0 and Ubuntu 8.04 AMI by Eric Hammond found at http://alestic.com.

class apache {
    # CentOS v.5 only
    case  $operatingsystem { 
     "CentOS":  { 
        $wantedpackages = [ "httpd","php","php-mysql","php-mcrypt","php-mhash","php-mbstring" ]
        package { $wantedpackages: 
                  ensure => installed 
        }
        service { "httpd":
                ensure => running,
                hasstatus => true,
                hasrestart => true,
                require => Package["httpd"],
                restart => true;
        }
      } 

    "Debian": { 
        # assume Debian base..
        $wantedpackages = [ "apache2" ]
        package { $wantedpackages: 
                  ensure => installed 
        }

        service { "apache2":
                hasstatus => true,
                hasrestart => true,
                ensure => running,
                require => Package["apache2"]
        }
    } 
  } # end case
} 

Obviously a web node will have the config:

node webA.sample.org {
   include apache 
}

Running it on EC2, pass a user-data script to the AMI during launch. A script that will set the hostname, adds default puppet master for the current instance and installs the puppetd. The puppetd program will then connect to the puppet server, and get all it’s needed configurations.

🙂 Thanks to Reductive labs.

A Simple Puppet Module Howto

With an assumption that Puppet master and client were successfully installed, here’s a simple tutorial how to create a simple module in puppet.

1. Create a directory modules on Puppet master /etc/puppet ( containing the subdirectory below):

 /etc/puppet/modules
 /test-file
 /files
 testmodule.txt
 /manifests
 init.php
 README

Where:
 testmodule.txt is a file to be copied.
 init.php contains the class

2. Edit /etc/puppet/puppet.conf on the server set modulepath.

[main]
server=puppet
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter
# set module here.
modulepath = /etc/puppet/modules

3. Edit the contents of modules/test-file/manifests/init.pp

class test-file::client {
   file { "/tmp/testmodule.txt":
       source=> "puppet://$servername/test-file/testmodule.txt"
   }
}

4. Edit the contents of /etc/puppet/manifests/site.pp

import "test-file"

class apache {
$wantedpackages = [ "apache2" ]
package { $wantedpackages: ensure => installed }
service { "apache2":
ensure => running,
hasrestart => true
 }
}

node default {
include apache
include test-file::client
}

5. Restart the puppetmaster:

 /etc/init.d/puppetmaster restart

6. On your puppet clients test:

 puppetd --waitforcert 60 --verbose --debug --test

7. Check if the testmodule.txt file is on the client’s /tmp folder.

References:
http://reductivelabs.com/trac/puppet/wiki/InstallationGuide#InstallPuppet
http://www.howtoforge.com/installing_puppet_on_ubuntu
HOWTO Install Puppet on CentOS 5.0
http://reductivelabs.com/trac/puppet/wiki/ModuleOrganisation