AWS OS provisioning using Ansible

AWS cloud configuration using Ansible..

Arvind Ramugade


Ansible is actually configuration management tool. However, we can use it to provision OS on AWS Cloud as well.

For this purpose we can use Controller node . In AWS O.S. can be launched using either of the following method

1. CLI
2. WebUI
3. API

AWS does not provide any managed node for configuring OS.
So, we have to use ansible code in local host and the connect to AWS server as a client.

In order to use API service we should have automated ansible code & SDK/library. Python supports boto3 which is a library for API.

We can install boto library using pip command.

Boto Library Installation

Next step is to create ansible playbook using ec2 module & provide required parameters as under

Ansible Playbook with EC2 Module

Point to note that we need to provide AWS credentials to login to environment .

For this we’ll need to create IAM user & note down Access Key & Secret Access key . We can include access keys sensitive information in a separate variable file & encrypt it using ansible-vault.

secret file

Above snippet shows that Ansible use AWS256 standard for Vault which is very secure.

Finally we can run ansible playbook & launch the EC2 instance.

EC2 dashboard before running Playbook

EC2 dashboard before running Ansible Playbook

EC2 dashboard after running ansible playbook

Ansible Playbook
EC2 instance launched successfully !!

Thus using Ansible we can launch EC2 instance in AWS cloud. So thus it can be used to provision OS on AWS cloud.

We can also decommission EC2 instance using Ansible playbook by specifying the instance id and changing the state

Ansible Playbook to Decommission EC2 instance
Ansible Playbook to shut down EC2 instance
EC2 Instance Suhtdown..
EC2 Instance Termination..

This proves that Ansible can also be used to provision OS on AWS apart from configuration management. This will be very useful business case when client wants to provision multiple EC2 instances at the same time.



Arvind Ramugade

Cloud Professional experienced in BFSI ,Telecom, Insurance domain with fortune 500 clients spread across USA, Europe, Canada, Australia and India.