Via G. Falcone 5, Pollenza (MC), Italy
+39 0733 203595

RDS infrastructure automation with Ansible

In this article we are going to describe how we realized our RDS infrastructure using Ansible as automation tool. We’ve completely avoided using AWS GUI, both for implementation and management activities.

Our aim was to develop a parametric infrastructure, able to adapt to all of our projects simply by changing few parameters in the config files.

Please note that at the time of writing we’re using Ansible 2.2.2.

First of all, we need to declare somewhere every needed variable. A var file, to be included where required, fits well.

Changing the file values it is possible to create N RDS servers and link them to the existing project’s VPC. As shown later, the infrastructure playbook will be invoked with a “rds_env” parameter. This way the infrastructure scripts can gather every VPC references for the project (specified by the “project” var) and create proper network connections towards the VPC itself.

Here are some examples of how it works:

Now the RDS networking is set up and we can move on to the RDS instances creation.

As you might guess, the number of instances is defined in the vars file:

Here is the full command for instances creation:

Moreover, we chose to assign a DNS name using Route53, to facilitate instances management:

Last but not least, we also chose to automate, thanks to Ansible, the whole environment destruction. Of course we set up strict controls to avoid destroying or corrupting production environments.

Here are some examples:

Now let’s glue the pieces together making use of a playbook, named infrastructure_rds.yml. As shown, secrets vars (db users, password, …) are kept in a different file.

Finally, for convenience, we wrapped it up with a bash script named infrastructure_rds.sh

Now the RDS infrastructure management is automated and written as code! We hope you can find it useful and remember that comments are always welcomed.

1 comment

Thank you a lot!

Leave a reply