Hello World module using template to Puppet
If you haven’t seen my previous tutorial you should see that:
How to install Puppet.
I’m using Xubuntu 12.04.03 32bit
Here is example how you can create template files to your Puppet module
Create folders and init.pp file
$ mkdir puppet/
$ cd puppet/
$ mkdir -p modules/hellotemplate/manifests/
$ nano modules/hellotemplate/manifests/init.pp
class hellotemplate {
$testVariable = 'I am variable from init.pp'
file { '/tmp/testModule':
content => template("hellotemplate/testTemplate.erb"),
}
}
Create folder to your template and template file
$ mkdir -p modules/hellotemplate/templates/
$ nano modules/hellotemplate/templates/testTemplate.erb
Create test content using facter variables
Greetings from template!
TestVariable: <%= @testVariable %>
Operating system release = <%= @operatingsystemrelease %>
<% if @operatingsystemrelease != "13.10" -%>
Time to change to a new release?
<% else -%>
You have the newest release!
<% end -%>
Apply your hellotemplate module
$ sudo puppet apply --modulepath modules/ -e 'class {"hellotemplate":}'
Test if file was created to your computer
$ cat /tmp/testModule
Greetings from template!
TestVariable: I am variable from init.pp
Operating system release = 12.04
Time to change to a new release?
Now you have created module that uses templates!
More facter variables you can find with
$ facter
$ sudo facter
$ sudo facter -p | less
These is what your folder/file tree should look like
puppet/
└── modules
└── hellotemplate
├── manifests
│ └── init.pp
└── templates
└── testTemplate.erb
4 directories, 2 files