Hello Puppet Module

By | 01/11/2013

I am writing this post as part of a course called Linuxin keskitetty hallinta (Linux centralized management) held by Tero Karvinen http://terokarvinen.com/2013/aikataulu-%E2%80%93-linuxin-keskitetty-hallinta-%E2%80%93-ict4tn011-4-syksylla-2013

I am using 64-bit Xubuntu 13.10 (Saucy Salamander) Fresh install. Everything on this post is done locally on one computer and not over a network to multiple computers.

The tasks of today’s assignment:

Study:

  • http://terokarvinen.com/2013/hello-puppet-revisited-%E2%80%93-on-ubuntu-12-04-lts
  • http://docs.puppetlabs.com/learning/ral.html
  • Do:
    Write a short puppet program based on the “Resources and the RAL” -chapter

    I started by installing puppet:
    $ sudo apt-get update && sudo apt-get install puppet

    I made a Hello World test with puppet by using the following command:
    $ puppet apply -e 'file { "/tmp/helloPuppet": content => "Hello Puppet World!n" }'

    And to read the file:
    $ cat /tmp/helloPuppet

    Hello Puppet World!
    

    I created new folders under my home directory in order to make a Hello World test to puppet modules
    $ mkdir -p puppet/modules/hello/manifests
    $ cd puppet
    $ nano modules/hello/manifests/init.pp

    class hello {
            file { '/tmp/helloModule':
                content => "Hello Puppet Module World!\n"
            }
    }
    

    I did the following in order to apply the change:
    $ puppet apply --modulepath modules/ -e 'class {"hello":}'

    And to see the new file:
    $ cat /tmp/helloModule

    Hello Puppet Module World!
    

    To test puppet out I edited the new file by adding a second row of text:
    $ nano /tmp/helloModule

    Hello Puppet Module World!
    This change will not stay...
    

    If you want to check the file afterwards:
    $ cat /tmp/helloModule

    To make puppet check the file again:
    $ puppet apply --modulepath modules/ -e 'class {"hello":}'

    Notice: /Stage[main]/Hello/File[/tmp/helloModule]/content: content changed '{md5}e5e4f24ae42ca15bfbf879c5044fcc6d' to '{md5}67e403ad5ec5407f691c6e08a65fea52'
    Notice: Finished catalog run in 0.08 seconds
    

    And re-check the content:
    $ cat /tmp/helloModule

    Hello Puppet Module World!
    

    The file is the same as before the edit.

    To finish the assignment I created new folders under the puppet directory with the following command:
    $ mkdir -p modules/apache2/manifests

    I created a new init.pp -file under manifests which contained the following:
    nano modules/apache2/manifests/init.pp

    class apache2 {
    
       	package { "apache2":
    		ensure => "installed"
    	}
    
    	service { "apache2":
            	ensure => "running",
            	enable => "true",
            	require => Package["apache2"],
        	}
    
    	exec { "userdir":
            	notify => Service["apache2"],
            	command => "/usr/sbin/a2enmod userdir",
            	require => Package["apache2"],
        	}
    }
    

    Now puppet should check if apache2 is installed and running. It also enables the use of public_html in users’ home directories.

    After sudo puppet apply --modulepath modules/ -e 'class {"apache2":}' Puppet installed apache2 and allowed the use of public_html.

    Next I navigated to my home directory and created the folder and added a simple html-file.
    cd
    mkdir public_html
    cd public_html
    nano index.html

    <!doctype html>
    <html>
    <head>
    	<title>Testing Apache2</title>
    </head>
    <body>
    	<p>This is HTML</p>
    </body>
    </html>
    

    After that I opened firefox and navigated to localhost/~samuel which showed the HTML page I had just created.

    Sources I used

4 thoughts on “Hello Puppet Module

  1. Pingback: Hello Puppet features | Samuel Kontiomaa

  2. Pingback: Installing Apache and PHP with Puppet module | Lauri Soivi

  3. Pingback: Puppet Hello World – Venla Taikatuuli Inkari

  4. Pingback: H3 | Portfolio

Leave a Reply

Your email address will not be published. Required fields are marked *