If we need to write, modify or test a puppet module, we can do it in several ways: we can modify our code in our puppet master directly (obviously not recommended) or we can create a new environment based in a git branch and use Directory Environments or we can configure puppet master and agent in our development workstation.
I think that this last option is particularly helpful every time I start a new puppet project, making the puppet development faster at the beginning of the project.
So, let’s install and configure both in one single node.
Cookbook
We will use Ubuntu 14.04 LTS (trusty) and Puppet 3.8.4
First of all we need to install puppetlabs repositories, but don’t worry, puppetlabs did most of the work for us.
Then we need to install puppet master and puppet agent, in this case we will specify the version in both packages.
Also and optionally, I like to install some tools in development environment that will help us in development process.
Now we need to configure both puppet services, we can do it using the same /etc/puppet/puppet.conf config file, just defining specific sections.
- [main] is the global section used by all commands and services. It can be overridden by the other sections.
- [master] is used by the puppet master service.
- [agent] is used by the puppet agent service.
Note that we enable reports and summaries in the agent section, this will help us during the module development. Also we enable the future parser to be ready for puppet 4.x versions.
Now we can restart puppet master
Because we used the environmentpath variable in the main section we will configure puppet with Directory Environments, making our puppet environment more flexible.
We need to create a new environment directory environments in /etc/puppet and then create a new environment with any name, in our case will be development.
We can leave the auth.conf and fileserver.conf files by default.
If you want to use hieradata integrated with the environments you need to create a hiera.yaml file with the proper configuration, for example…
Each environment should have the standard tree directory with hieradata, manifests and modules, and also an environment.conf file where we need to define/overwrite some puppet variables.
Now we can define our default.pp and localhost.pp nodes in the manifests directory
And finally we can test our puppet configuration running puppet agent
Now you can start to write your puppet modules inside /etc/puppet/environments/development/modules.
That’s all!
Comments