Linuxin keskitetty hallinta – Homework 1 – Hello Puppet

Course homepage:

Updated 4.4.2013 to make use of updated module instructions at


I’ve set up a virtual machine in Virtualbox, running Xubuntu 12.10, for use during the course.

  • The main user is master
  • the computer name is palvelin
  • It has a static internal IP address: 
  • ufw is enabled, allowing only TCP traffic to port 80

The host system has an Intel Core 2 Quad processor and 8GB of physical RAM and is running Windows 7 x64.


Our first piece of homework consisted of a brief assignment in addition to reading up on Puppet basics:

Write a short puppet program using as reference.


The main user, master, has trouble controlling his webpage editing impulses. The system has the apache2 web server with the userdir mod enabled, which leaves him free to edit /home/master/public_html/index.html

He has decided to see into using a simple puppet module to:

  • replace his strange site modifications with a stern reminder
  • install the package ‘nethack-console’ as an alternative


Building the basic environment

I’ll start with a compact list of the necessary commands for building the aforementioned environment on the virtual machine. These are discussed and demonstrated in-depth in the homework entries for the previous course

master@palvelin:~$ sudo apt-get update
master@palvelin:~$ sudo ufw enable
master@palvelin:~$ sudo ufw allow http
master@palvelin:~$ sudo apt-get install apache2
master@palvelin:~$ sudo a2enmod userdir
master@palvelin:~$ sudo service apache2 restart

Index.html for master

Let’s create the default webpage for master:

master@palvelin:~$ mkdir public_html
master@palvelin:~$ nano ./public_html/index.html

whose contents are:

<!doctype html>
<title>A puppet placeholder</title>
<meta charset="utf-8" />
<h1>I'm a little teapot</h1>
<p>Hear me shout</p>

which looks like this in the browser:



Creating a puppet module

The modules’ files will reside in puppet/modules under master’s homedir. For now, we create a file called init.pp for a module called pagefix, like so:

master@palvelin:~$ mkdir -p puppet/modules/pagefix
master@palvelin:~$ nano ./puppet/modules/pagefix/init.pp

whose contents are:

class pagefix {
file { '/home/master/public_html/index.html':
ensure => present,
content => "no."
package { 'nethack-console':
ensure => present,

This essentially makes puppet ensure that master’s index.html exists, and replace its contents with the string “no.” It also installed the game nethack-common from the Ubuntu repositories.

Applying the module

We test the module by puppet apply which will be run as sudo, since it installs a program. It’s followed by the absolute path to the module file, like so:

master@palvelin:~$ sudo puppet apply --modulepath /home/master/puppet/modules/ -e 'class {"pagefix":}'

whose output looks like this:

warning: Could not retrieve fact fqdn
notice: /Stage[main]//Package[nethack-console]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[main]//File[/home/master/public_html/index.html]/content: content changed '{md5}14895bce9da04654396bc6cf2aaeae13' to '{md5}1bfd7f653591e54b5c9c4e428c65f608'
notice: Finished catalog run in 5.55 seconds

Note the warning about not being able to retrieve fact fqdn. This could supposedly be alleviated by adding something.or.other to the HOSTS file. The check adds an extra 5 seconds or so to the action.


Let’s see if the web page changed:


It certainly did. Let’s try running nethack:


Seems to have installed just fine. Applying the module again wouldn’t modify the system further, as the resources’ desired state is the status quo.


About a1100320

IT student, musician, gamer. Beep boop.
This entry was posted in Linuxin keskitetty hallinta ICT4TN011-3. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s