Define Types

In this tutorial I’m creating hello_define module that uses Puppet define types. Hello_define module creates two files with different content.

If you haven’t seen my previous tutorials you should see them:
How to install Puppet, Hello World module using template to Puppet,
Installing Apache and PHP with Puppet module, Installing Puppet master and slaves, Parametrized Class with Puppet.

I’m using Xubuntu 12.04.03 32bit

Install and create

Update apt and use it to install Puppet

$ sudo apt-get update && sudo apt-get -y install puppet

Create folders where you add your init.pp file

$ mkdir puppet/
$ cd puppet/
$ mkdir -p modules/hello_define/manifests/

Then create init.pp file and modify it

$ nano modules/hello_define/manifests/init.pp

Make hello_define class that creates two files with different content using define types. Modify your init.pp file look like this

class hello_define {
    define hello_define ($content_variable) {
      file {"$title":
        ensure  => file,
        content => $content_variable,
      }
    }

    hello_define {'/tmp/hello_define1':
      content_variable => "Hello World. This is first define\n",
    }

    hello_define {'/tmp/hello_define2':
      content_variable => "This is my second define. Greeting from soivi.net\n",
    }
}

Apply Define Types

Apply hello_define module with Puppet.

$ puppet apply --modulepath modules/ -e 'class {"hello_define":}'

Now hello_define module has created two files. Files are in /tmp/ folder. You can cat those files and see what are inside them

$ cat /tmp/hello_define1 
Hello World. This is first define

$ cat /tmp/hello_define2
This is my second define. Greeting from soivi.net

The folder tree looks now like this

puppet/
└── modules
    └── hello_define
        └── manifests
            └── init.pp

Comment and let me know what you think of this guide. Did you manage to do hello_define module? Was there something incorrect?

I used Puppet in this blog post. Puppet is create way to centralize manage many computers at the same time. You should check it out. I have created couple beginners guides. If you want to learn more you should check them out:
How to install Puppet, Hello World module using template to Puppet,
Installing Apache and PHP with Puppet module, Installing Puppet master and slaves, Parametrized Class with Puppet.