This is not the first time that 2ndQuadrant has looked at Puppet. Gabriele Bartolini has already written an article in two parts on how to rapidly configure a PostgreSQL server through Puppet and Vagrant, accompanied by the release of the code used in the example on GitHub (http://github.com/2ndquadrant-it/vagrant-puppet-postgresql).
Split into three parts, the aim of this article is to demonstrate automation of the setup and configuration of Barman to backup a PostgreSQL test server.
This article is an update of what was written by Gabriele with the idea of creating two virtual machines instead of one, a PostgreSQL server and a Barman server.
it2ndq/barman
is the module released by 2ndQuadrant Italy to manage the installation of Barman through Puppet. The module has a GPLv3 licence and is available on GitHub at the address http://github.com/2ndquadrant-it/puppet-barman. The following procedure was written for an Ubuntu 14.04 Trusty Tahr but can be performed in a similar manner on other distributions.
Requirements
To start the module for Barman on a virtual machine, we need the following software:
Vagrant
Vagrant is a virtual machine manager, capable of supporting many virtualisation softwares with VirtualBox as its default.
We install VirtualBox this way:
|
The latest version of Vagrant can be downloaded from the site and installed with the command:
|
Ruby
Regarding Ruby, our advice is to use rbenv
, which creates a Ruby development environment in which to specify the version for the current user, thereby avoiding contaminating the system environment. To install rbenv
we suggest to use rbenv-installer
(http://github.com/fesplugas/rbenv-installer).
Let’s download and execute the script:
|
At the end, the script will prompt you to append the following lines to the ~/.bash_profile
file:
|
We now need to reload the just changed ~/.bash_profile
:
|
At this point, we locally install a Ruby version (in this case, 2.1.5) and set the user to run this version rather than the system version:
|
Puppet
Puppet is required not only on the VMs but also on the machine running them. Therefore we need to install the Puppet gem.
|
Librarian-puppet
Finally, librarian-puppet
is a tool to automate the Puppet modules management. Like Puppet, librarian-puppet
can be installed as a gem:
|
Vagrant: configuration
Now that we have the dependencies in place, we can start to write the Vagrant and Puppet configurations for our backup system.
We start by creating a working directory:
|
Vagrant needs us to write a file called Vagrantfile
where it looks for the configuration of the VMs.
The following Vagrantfile
starts two Ubuntu Trusty VMs, called pg
and backup
, with ip addresses 192.168.56.221
and 192.168.56.222
. On both machines provisioning will be performed through an inline shell script.
This script launches puppet-bootstrap
(http://github.com/hashicorp/puppet-bootstrap), a script that automatically installs and configures Puppet on various types of machines. As it does not need to be run more than once, in the script a test was inserted to prevent further executions.
|
Bringing up the VMs
We have defined two Ubuntu Trusty VMs containing Puppet. This is not the final Vagrantfile
but already allows the creation of the two machines. If you’re curious, it is possible to verify that the two machines have been created with the command:
|
and then connecting using the following commands:
|
Finally, the machines can be destroyed with:
|
Conclusions
In this first part of the tutorial we’ve seen how to configure the dependencies and ended up with the two virtual machines on which we’ll install, via Puppet, PostgreSQL and Barman. Writing the Puppet manifest for the actual installation will be the subject of the next article.
Bye for now!