Puppet module for LAMP installation

We are using Puppet in the course I spoke of before and we’re creating our own Puppet modules. Here’s what I came up with. A module that installs a LAMP server( LAMP = Linux Apache MySQL PHP) in two different ways to two different nodes. The lamp module has slightly more features than the easylamp. For example it changes the mysql password which is missing from the easylamp module. The modules might not be very sophisticated as these are some of the first Puppet modules I’ve ever made. Have to start somewhere!

UPDATE 6.10.2012: I have made improvements to the LAMP module and there’s a new blog post about it here:
http://awaseroot.wordpress.com/2012/10/06/improved-puppet-lamp-module/

Puppetmaster = Ubuntu 12.04
Puppet agents = Ubuntu 11.10
Puppet version 2.7.11

Modules and manifests

manifests/site.pp

node default {}

node 'bubuntu.elisa' {
    include lamp
}

node 'hubuntu.elisa' {
    include easylamp
}

modules/lamp/manifests/init.pp

class lamp {

    Package { ensure => "installed" }

    package { "apache2": }
    package { "apache2.2-common": }
    package { "php5": }
    package { "libapache2-mod-auth-mysql": }
    package { "php5-mysql": }
    package { "mysql-server": }
    package { "phpmyadmin":}

    exec { "mysqlpasswd":
        command => "/usr/bin/mysqladmin -u root password ChangeThis1",
        notify => [Service["mysql"], Service["apache2"]],
        require => [Package["mysql-server"], Package["apache2"]],
    }

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

    service { "mysql":
        ensure => "running",
        enable => "true",
        require => Package["mysql-server"],
    }

    exec { "userdir":
        notify => Service["apache2"],
        command => "/usr/sbin/a2enmod userdir",
        require => Package["apache2"],
    }

    file { "/etc/apache2/mods-available/php5.conf":
        notify => Service["apache2"],
        ensure => "present",
        source => "puppet:///modules/lamp/php5.conf",
        owner => "root",
        group => "root",
        mode => 644,
        require => [Package["apache2"], Package["php5"]],
    }

    file { "/var/www/index.php":
        notify => Service["apache2"],
        ensure => "present",
        source => "puppet:///modules/lamp/index.php",
        owner => "root",
        group => "root",
        mode => 644,
        require => [Package["apache2"], Package["php5"]],
    }

    file { "/etc/apache2/apache2.conf":
        notify => Service["apache2"],
        ensure => "present",
        source => "puppet:///modules/lamp/apache2.conf",
        owner => "root",
        group => "root",
        mode => 644,
        require => [Package["apache2"], Package["phpmyadmin"]],
    }
}

modules/lamp/files/apache2.conf
This is the default apache2.conf with this added to the end:

include /etc/phpmyadmin/apache.conf

modules/lamp/files/index.php

<?php echo "THIS PAGE IS MANAGED BY PUPPET";?>

modules/lamp/files/php5.conf
This is the default php5.conf except that the userdir module lines are commented

modules/easylamp/manifests/init.pp

class easylamp {

    package { "tasksel":
        ensure => "installed",
    }

    exec { "lamp":
        command => "/usr/bin/tasksel install lamp-server",
        require => Package["tasksel"],
    }

    file { "/var/www/index.php":
        ensure => "present",
        content => "<?php phpinfo();?>",
        owner => "root",
        group => "root",
        mode => 644,
        require => Exec["lamp"],
    }

    file { "/etc/apache2/mods-available/php5.conf":
        notify => Service["apache2"],
        ensure => "present",
        source => "puppet:///modules/easylamp/php5.conf",
        owner => "root",
        group => "root",
        mode => 644,
        require => Exec["lamp"],
    }

    service { "apache2":
        ensure => "running",
        enable => "true",
        require => Exec["lamp"],
    }
}

modules/easylamp/files/php5.conf
This is the default php5.conf except that the userdir module lines are commented

Tests
The Puppetmaster and the agents were set up according to this tutorial:
http://terokarvinen.com/2012/puppetmaster-on-ubuntu-12-04

Test to see if the installed parts are working:

bubuntu.elisa (lamp module):
firefox http://localhost
Shows “It works!” site.
Confirms that apache2 is working.

firefox http://localhost/index.php
Shows “THIS PAGE IS MANAGED BY PUPPET”.
Confirms that PHP is working.

firefox http://localhost/phpmyadmin
Shows the phpmyadmin login.
Confirms that phpmyadmin is working.

mysql -u root --password=ChangeThis1
“Welcome to the MySQL monitor…..”
Confirms that MySQL is working.

You can change the mysql password with this command:
mysqladmin -u root --password=ChangeThis1 password [new password]

hubuntu.elisa (easylamp module):
firefox http://localhost
Shows “It works!” site.
Apache2 is working.

firefox http://localhost/index.php
Shows the php info.
PHP is working.

mysql
Error – Access denied.
MySQL is working but the password is not set (as intended).

You can also find all of the module files from the awaseroot github:
https://github.com/awaseroot/awaseroot/tree/master/puppet/old

Improved module is also on our github here:
https://github.com/awaseroot/awaseroot/tree/master/puppet/modules/lamp

Sources:
http://wiki.ubuntu-fi.org/LAMP_Asennus
http://www.kyberkeikka.fi/2010/05/asennusopas-lamp-linux-apache-mysql-php.html
http://terokarvinen.com/2012/puppetmaster-on-ubuntu-12-04

About these ads

7 responses to “Puppet module for LAMP installation

  1. Pingback: Subsys lock problem with CentOS 6.2 and Apache « awaseroot

  2. Pingback: Improved Puppet LAMP module « awaseroot

  3. Vide January 28, 2013 at 1:18 pm

    You should be more modular. Instead of using one “lamp” class you should use a LAMP role (which in turns would be a class, of course) which includes different, separated and generic modules, one for each software you need in a LAMP installation (Apache, MySQL, PHP, whatever).

  4. Pingback: Oma puppet moduli – Linuxin keskitetty hallinta | Aleksi J

  5. Pingback: Linuxin keskitetty hallinta – Final assignment – Lighttpd (userdir enabled) and Varnish with Puppet | IT homework blog

  6. Pingback: Hello Puppet Module | Samuel Kontiomaa

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.

%d bloggers like this: