Puppet – Your First Class

Previous post: How to Install Puppet Agent in Windows

In this post we will create a simple class. We will also make the necessary configuration so that the classes can be seen in Foreman. At the moment there is no class defined.

Open a terminal window in your Puppet server and go to folder “/etc/puppet/modules”. This is the place for your definitions. As a starting example we will only create a simple class which installs vim text editor.

Here are the steps:
– First create a folder with the name of your class.
– Go into the folder and create a “manifests” folder.
– Go into manifests folder and create a file named “init.pp”

$ sudo -i 
# cd /etc/puppet/modules
# mkdir vim
# cd vim 
# mkdir manifests
# cd manifests
# nano init.pp

Here is the contents of init.pp

class vim {
    package { 'vim':
       ensure => present,

After saving the file. We will continue with foreman. Go to foreman web user interface and "Configure -> Puppet Classes“. And click on “Import from yourserver

Puppet - Your First Class

After that you will see environments “common, development, production, example_env“.  You can import and activate your class for different environments. In this example I will do it only for production. After clicking “Update” you will see that the class is imported.

foreman puppet classes2

Now the last step is to assign it to hosts. Select “Hosts -> All hosts” from the menu. You will see the list of hosts. Select “Edit” one of them.

foreman puppet classes3

Go to Puppet Classes tab and select the class as seen in the screenshot below:

foreman puppet classes4

After that submit the changes. Now you can go to the host and run “puppet agent -t” to see what happens.

$ sudo puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for ubuntutest.example.com
Info: Applying configuration version '1415091621'
Notice: /Stage[main]/Vim/Package[vim]/ensure: ensure changed 'purged' to 'present'
Notice: Finished catalog run in 20.92 seconds

As you can see it installed the vim package successfully.