Author Archives: admin

Using Puppet to install Tomcat,MySQL, SVN and Java

In the last blog which features creating a basic module in Puppet here and here, this is a sample init.pp I’ve created to install, tomcat,mysql,subversion,java1.5 and load a database from a dump file. Notice that JDK is installed while accepting the license by using debconf-utils package. Tested in Ubuntu hardy which is launch from Amazon EC2.

Hope this will help some of my friends in their Puppet configurations.

class hostmanager::server {
     file { "/root/db.sql":
         source=> "puppet://$servername/hostmanager/db.sql"
     }
     file { "/etc/init.d/tomcat5.5":
         source=> "puppet://$servername/hostmanager/tomcat5.5"
     }
     $wantedpackages = ["debconf-utils", "mysql-server", "subversion"]
     package { $wantedpackages: ensure => installed }
     package { ["sun-java5-jdk"] :
                   ensure => installed,
                   require => Exec ["accept-license"]
     }
     package { ["tomcat5.5"] :
                   ensure => installed,
                   require => Package["sun-java5-jdk"]
     }
     exec { "informdb-load":
                 command => "mysql < /root/db.sql",
                 path =>"/bin:/usr/bin",
                 subscribe => File["/root/db.sql"],
                 subscribe => Service["mysql"],
                 unless => "mysql informdb -e 'quit'"
                }
      exec { "accept-license":
               command => "echo 'sun-java5-bin   shared/accepted-sun-dlj-v1-1    boolean true<br /> sun-java5-jdk   shared/accepted-sun-dlj-v1-1    boolean true
               sun-java5-jre   shared/accepted-sun-dlj-v1-1    boolean true
               sun-java5-jre   sun-java5-jre/stopthread        boolean true
               sun-java5-jre   sun-java5-jre/jcepolicy note
               sun-java5-bin   shared/present-sun-dlj-v1-1     note
               sun-java5-jdk   shared/present-sun-dlj-v1-1     note
               sun-java5-jre   shared/present-sun-dlj-v1-1     note
               '|debconf-set-selections",

               path =>"/bin:/usr/bin",
               subscribe =>Package["debconf-utils"]
          }
          service { "tomcat5.5":
                ensure => running,
                hasstatus => true,
                hasrestart => true,
                require => Package["tomcat5.5"],
                require => File["/etc/init.d/tomcat5.5"],
               restart => true
         }
         service { "mysql":
               ensure => running,
               hasstatus => true,
               hasrestart => true,
               require => Package["mysql-server"],
               restart => true
        }
}

Let’s start learning more about puppet. 🙂

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.