AWS Infrastructure Creation with Ansible Part-2

In the second part of this series of tutorials, we’ll create the Security Group and EC2 Key Pair using Ansible. If you didn’t create the VPC already, then please check the Part-1 of this series.

If you have completed the Part-1, then you have already clone the git repo that contains all the roles, if not then clone the git repo:

git clone https://github.com/arbabnazar/ansible-aws-roles.git
cd ansible-aws-roles

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

May be, you have already noticed that we have also added the vpc role in the playbook, it will not re-create the vpc, if you have created it in the first part, because Ansible is idempotent.

Review/modify the variable file for Security Groups, see roles/ec2sg/defaults/main.yml:

Also review/modify the variable file for EC2 Key Pair, see roles/ec2key/defaults/main.yml:

For creating the EC2 Key Pair, you have two options:

  • Generate the Local RSA Key, if it doesn’t have and use the public part of it
  • Fetch your public key from github and use it

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 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 the vpc role in the playbook:

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

Else use this command if you have not added the vpc role in the playbook:

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

sg

key

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

security-groups

key

Enjoy :-)

Hope this will help you!

Please Remember me in your prayers!

In next post, we’ll create the EC2 Instance using these resources.

Advertisements

3 responses to “AWS Infrastructure Creation with Ansible Part-2

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

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

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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: