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.
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.
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.
The bootstrap script is called at the end of the file. It encapsulates the custom applications to install for this little project.
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.
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.
Finally, the packages make, git client, Pip for Python3 and Ansible are installed.
Run vagrant up command and provision the vm. Ssh into the vm with the default Vagrant ssh key or use vagrant ssh.
The following steps are just to check, if the vm is working.
Create a local collection zipfile with make.
Change to the test directory and install the requirements with Pip.
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.
Check the log output to validate a successful run.
In case of an error, clean up the failed test or start debugging.
You are now good to go and contribute to the edb-ansible collection.