lauantai 6. huhtikuuta 2013

Puppet modules and classes

Puppet Templates / Puppet Modules

Puppet modules can include multiple manifests, files and many things. Whole manifest is put inside class modulename {} and make a working folder hierarchy for it.

So I went to /etc/puppet/modules
$ cd /etc/puppet/modules
and created a new module named apache2
$ mkdir apache2; cd apache2; mkdir manifests
then I created new init.pp file
$ nano init.pp
And here is the text for my manifest it installs apache2 and makes sure it is runnig, then creates a new directory in /var/www/testsite and adds empty index.html file:

# this manifest installs apache2

class apache2 {

#Ensure that apache2 is installed and running
package { 'apache2':
ensure => installed,
}

service {'apache2':
ensure => running,
}

#Ensure there is directory for our site
file { '/var/www/testsite':
ensure => directory,
#Rear and write for me, read for others.
mode => 644,
}

#Ensure that we have index page in testsite
file {'/var/www/testsite/index.html':
ensure => file,
}
}

And to reveal it
$ sudo puppet apply -e "include apache2"
Which seems to work!


Now I can include the class from any manifest, without having to cut and paste anything.

TEMPLATES

Template is a file in somewhere which content is copied. Template file ending is .erb

I added this line under the ensure index.html is present:
content => template ("/home/shnigi/templeitti.erb"),

Then I created a new file named templeitti.erb in /home/shnigi/ and added some HTML code to it.

$ sudo puppet apply -e "include apache2"

Everything went fine in terminal, then I pointed my browser to http://localhost/testsite/ and noticed the html was copied from the erb file to the index.html file. I'm starting to understand this thing.

Ei kommentteja:

Lähetä kommentti