Joni Junni

Some Puppet module testing

Categories: [school]
Tags: [linux], [puppet], [linux-centralized-management-course], [apache], [debian], [vm]

After I got Puppet running in my test VM, I wanted to test some simple tasks it could do. After reading the chapter Resources and the RAL from Puppet documentation, I started to test it on my test VM.

Creating a user

I started testing with user creation. I created the default module directory structure for the module “puppetUserTest”:

mkdir -p puppetUserTest/manifests

(The -p argument lets us to create the two directories with one command.)

Then I started to write the init.pp file that is needed for Puppet modules:

nano /puppetUserTest/manifests/init.pp

I wrote the following code to the file:

class puppetUserTest {
    user { 'puppetUser':
        ensure => 'present',
        home => '/home/puppetUser',
        shell => '/bin/bash'
    }
}

Then I saved the file and tested it with the following command (sudo is needed in this case as I am creating a user):

sudo puppet apply puppetUserTest/manifests/init.pp

create-puppetuser

And voilà, we have a new user in the system:

puppetuser-created

Listing from /etc/passwd file.

Installing a software package

Next I tested if I could simply install Apache Web Server to my VM and check that it was started.

Again I created a new directory structure with the following command:

mkdir -p installApache2/manifests

Then I created the configuration file with the command:

nano installApache2/manifests/init.pp

I wrote the following configuration to the file:

class installApache2 {
    # Install Apache2 if it isn't already
    package { 'apache2':
        ensure => installed,
    }

    # Ensure that Apache2 is running
    service { 'apache2':
        ensure => running,
        enable => true,
    }
}

After I was done with the configuration, I made a test run on it with the command:

sudo puppet apply installApache2/manifests/init.pp

So, the result was a wall of text with error messages:

apache2-install-errors

As I investigated the resolving errors, I found out that my internet connection was down. When I switched over to mobile broadband, I was able to continue to try again my puppet module.

apache2-installed

From the process listing we can see that apache2 is running. I tested if it was really working by going to the server with a browser:

working-apache

Yay, it works!

Conclusion

As I made these tests on my test VM, I was amazed how simple it was to make these config files. It took me less than an hour to do all this, including writing this post which took most of the time.

Sources