forked from akannan1087/myAnsibleInfraRepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-redhat-ec2.xml
More file actions
56 lines (51 loc) · 1.61 KB
/
Copy pathcreate-redhat-ec2.xml
File metadata and controls
56 lines (51 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
- name: provisioning EC2 Lab Exercises using Ansible
hosts: localhost
connection: local
gather_facts: False
tags: provisioning
vars:
keypair: myAug2019Key
instance_type: t2.micro
image: ami-0520e698dd500b1d1
wait: yes
group: webserver
count: 1
region: us-east-2
security_group: nexus_group_2020
tasks:
- name: Create a security group
local_action:
module: ec2_group
name: "{{ security_group }}"
description: Security Group for webserver Servers
region: "{{ region }}"
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 8081
to_port: 8081
cidr_ip: 0.0.0.0/0
rules_egress:
- proto: all
cidr_ip: 0.0.0.0/0
register: basic_firewall
- name: Launch the new EC2 Instance
local_action: ec2
group={{ security_group }}
instance_type={{ instance_type}}
image={{ image }}
wait=true
region={{ region }}
keypair={{ keypair }}
count={{count}}
register: ec2
- name: Add the newly created EC2 to the local host group
local_action: lineinfile
dest="/etc/ansible/hosts"
regexp={{ item.public_ip }}
insertafter="[webserver]" line={{ item.public_ip }}
with_items: "{{ ec2.instances }}"