Spinning EC2 instance using Ansible

## Demo playbook to set up EC2 instance
# 1. Creates a custom security group
# 2. Spins new EC2 instances
# 3. Waits for ssh to become active on Instance
- hosts: localhost
tasks:
- name: Setting up Security / Firewall Group
ec2_group:
name: AWS_Rajeev_Sec_Grp
description: Rules Allowing traffic on port 22 and 80
region: us - east - 2
rules:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0 / 0
rules_egress:
- proto: all
cidr_ip: 0.0.0.0/0
- name: Provision a EC2 Instance
ec2:
key_name: Rajeev - AWSKey
region: us - east - 2
instance_type: t2.micro
image: ami - 775e9
d21
wait: yes
wait_timeout: 500
count: 1
instance_tags:
Name: awslabserver
Owner: Rajeev
monitoring: no
vpc_subnet_id: subnet - 310
c40f7
assign_public_ip: yes
group: Rajeev_AWS_Sec_Grp
register: ec2_out
- name: Wait
for SSH to come up
wait_for: host = {{item.public_dns_name}}
port = 22
delay = 60
timeout = 320
state = started
with_items: '{{ec2_out.instances}}'

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store