A customer recently required assistance in automating their PostgreSQL installation with Ansible. EDB’s edb-ansible collection provides all the required functionality and was used by me to provide the required playbooks. First, I had to deal with one problem: my notebook runs Windows 10. So, I decided to take care of it with a small Linux vm, created with Vagrant and Virtualbox. I’d like to show in this blog post the steps which are implemented to have an out-of-the-box environment to start working.

The Vagrantfile with the bootstrap script are available from my Github repository.

Vagrant VM Configuration

First, I’ll start with the vm and its configuration in the Vagrantfile. The file evolved over time and provides the option to create several vms. In this case, I just need one vm which is called „server8“, runs Ubuntu and uses 3 CPU cores, 8 GB RAM and a static IP address.

Copy to Clipboard
For comfort reasons, two Vagrant plugins are used. vagrant-vbguest automatically installs the Virtualbox guest additions and vagrant-hostmanager modifies the host’s and vm’s hosts file to enable resolution of multi-machine environments.
Copy to Clipboard
The rest of the script loops through all configured vms, this time only once, and provisions the vm. A common set of configuration options is always used, e.g. disable usb.
Copy to Clipboard
The bootstrap script is called at the end of the file. It encapsulates the custom applications to install for this little project.
Copy to Clipboard

Bootstrap Script

Let’s go into details for the bootstrap script, which is just a bash script. First, the list of all available packages is updated and second, all installed packages are upgraded.
Copy to Clipboard
Based on Docker’s documentation, the convenience script is run to install docker. The user vagrant is added to the docker group to be able to run container.
Copy to Clipboard
The next code block makes sure, that the latest release of docker compose plugin is installed. It is one requirement to run the tests for the edb-ansible collection.
Copy to Clipboard
Finally, the packages make, git client, Pip for Python3 and Ansible are installed.
Copy to Clipboard
Run vagrant up command and provision the vm. Ssh into the vm with the default Vagrant ssh key or use vagrant ssh.
Copy to Clipboard

Ansible Collection Test

The edb-ansible repository includes the documentation for contribution and testing.
The following steps are just to check, if the vm is working.
Copy to Clipboard
Create a local collection zipfile with make.
Copy to Clipboard
Change to the test directory and install the requirements with Pip.
Copy to Clipboard
The different roles require either a free account for the EDB repository or use the Postgres Development Group’s repository.

 

In this example, the EDB repository is used to run the test case to initialize a cluster on Ubuntu 20. Refer to the test documentation to get a full list of features and how to test.
Copy to Clipboard
Check the log output to validate a successful run.
Copy to Clipboard
In case of an error, clean up the failed test or start debugging.
Copy to Clipboard
You are now good to go and contribute to the edb-ansible collection.