A Simple Puppet Module Howto

With an assumption that Puppet master and client were successfully installed, here’s a simple tutorial how to create a simple module in puppet.

1. Create a directory modules on Puppet master /etc/puppet ( containing the subdirectory below):

 /etc/puppet/modules
 /test-file
 /files
 testmodule.txt
 /manifests
 init.php
 README

Where:
 testmodule.txt is a file to be copied.
 init.php contains the class

2. Edit /etc/puppet/puppet.conf on the server set modulepath.

[main]
server=puppet
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter
# set module here.
modulepath = /etc/puppet/modules

3. Edit the contents of modules/test-file/manifests/init.pp

class test-file::client {
   file { "/tmp/testmodule.txt":
       source=> "puppet://$servername/test-file/testmodule.txt"
   }
}

4. Edit the contents of /etc/puppet/manifests/site.pp

import "test-file"

class apache {
$wantedpackages = [ "apache2" ]
package { $wantedpackages: ensure => installed }
service { "apache2":
ensure => running,
hasrestart => true
 }
}

node default {
include apache
include test-file::client
}

5. Restart the puppetmaster:

 /etc/init.d/puppetmaster restart

6. On your puppet clients test:

 puppetd --waitforcert 60 --verbose --debug --test

7. Check if the testmodule.txt file is on the client’s /tmp folder.

References:
http://reductivelabs.com/trac/puppet/wiki/InstallationGuide#InstallPuppet
http://www.howtoforge.com/installing_puppet_on_ubuntu
HOWTO Install Puppet on CentOS 5.0
http://reductivelabs.com/trac/puppet/wiki/ModuleOrganisation

1 thought on “A Simple Puppet Module Howto

  1. Pingback: Using Puppet to install Tomcat,MySQL, SVN and Java

Leave a Reply

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