Provision AWS using Ansible

let’s go

requirements

ubuntu 18.04
ansible
python3
windows
virtualbox

Setup environment
ssh into the virtualbox running ubuntu 18.04 using cygwin/gitbash

$ pip3 install boto boto3
$ pip3 install awscli
$ sudo apt update
$ sudo apt install ansible

create IAM user

create IAM user
select Programmatic access
policy for the user

configure accesskey and secret key

$ aws configure
AWS Access Key ID [*************NVPP]:
AWS Secret Access Key [***************Fyu7]:
Default region name [ap-south-1]:
Default output format [None]:

ansible playbook

- name: ec2 launcher
hosts: localhost
tasks:
- name: launching ec2
ec2:
instance_type: t2.micro
key_name: ****-key
image: ami-******
region: ap-south-1
group: default
count: 1
vpc_subnet_id: subnet-******
wait: yes
assign_public_yes: yes

run the playbook

$ ansible-playbook task.yml --extra-vars "ansible_python_interpreter=/usr/bin/python3"

output

output
aws console

NOTE:

  1. Ansible will connect to the AWS using bot SDK.
    so install both boto, boto3 packages.
  2. boto will handle the connections behind the scenes
    the ec2 instance still doesn’t exist yet, so simply point ansible
    to localhost.

[Reference]

https://www.freecodecamp.org/news/ansible-manage-aws/

thats all folks…take it easy

now or never