AWS Infrastructure Creation with Ansible Part-4

By this point, you should have gone through the Part-1, Part-2 and Part-3 of this series. In this tutorial, we’ll create the RDS instance inside the VPC that we have created in Part-1  and Security Group created in Part-2 using Ansible.

If you have completed the previous parts of this series, then you have already clone the git repo that contains all the roles, if not then clone the git repo:

git clone
cd ansible-aws-roles

Modified the aws.yml playbook to add the desired roles:

Note: May be, you have already noticed that we have also added the vpc, ec2sg, ec2key, ec2instance and elb roles in the playbook, it will not re-create all this except the EC2 instance(this role is not idempotent), if you have created them in the previous parts, because Ansible is idempotent.

Review/modify the variable file for EC2 Instance, see roles/rds/defaults/main.yml:

We need to modify the values of all the variables that are uppercase. For this, we’ll set them in the external file(in my case, it is secret.yml) which already contains our VPC,Security Groups and EC2 Key Pair variables:

This file must keep in secret place and encrypt with ansible vault.

Once you are all set with the variables, then run this command if you have added all the roles in the playbook:

ansible-playbook -i inventory/hosts aws.yml -e@secret_vars/secret.yml

But please note that it will create the EC2 instance, even you have already created.

Else use this command if you have not added the vpc and security group roles in the playbook:

ansible-playbook -i inventory/hosts aws.yml-e@secret_vars/secret.yml -e@secret_vars/rbgeek-dev.yml

After successful completion of playbook, login to the AWS Web Console and verify the resources:



Extra Info: I have written a simple lookup plugin to find the Security Group ID from it’s name because RDS instance module only accept the ID, not the name:

Enjoy :-)

Hope this will help you!

Please Remember me in your prayers!

One response to “AWS Infrastructure Creation with Ansible Part-4

  1. Pingback: AWS Infrastructure Creation with Ansible Part-3 | Lazy Geek -:)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: