Linuxin keskitetty hallinta – Homework 1 – Hello Puppet

Course homepage: http://terokarvinen.com/2012/aikataulu-linuxin-keskitetty-hallinta-ict4tn011-3

Updated 4.4.2013 to make use of updated module instructions at http://terokarvinen.com/2013/hello-puppet-revisited-%E2%80%93-on-ubuntu-12-04-lts

Environment

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: 192.168.1.220 
  • 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.

Assignment

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

Write a short puppet program using http://docs.puppetlabs.com/learning/ral.html as reference.

Scenario

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

Walkthrough

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 https://a1100320.wordpress.com/category/linux-palvelimena-ict4tn003-4/:

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>
<html>
<head>
<title>A puppet placeholder</title>
<meta charset="utf-8" />
</head>
<body>
<h1>I'm a little teapot</h1>
<p>Hear me shout</p>
</body>
</html>

which looks like this in the browser:

teapot

Awful.

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 127.0.0.1 something.or.other to the HOSTS file. The check adds an extra 5 seconds or so to the action.

Results

Let’s see if the web page changed:

no

It certainly did. Let’s try running nethack:

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.

Advertisements

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:

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