-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.yml
84 lines (71 loc) · 2.19 KB
/
main.yml
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
- name: "AWS EC2 creation using Ansible-playbook"
hosts: localhost
vars:
project: "Uber"
region: "ap-south-1"
instance_type: "t2.micro"
instance_ami: "ami-0e0ff68cb8e9a188a"
tasks:
- name: "AWS Infra - Creating Ssh-Key Pair"
amazon.aws.ec2_key:
name: "{{project}}"
state: present
tags:
Name: "{{ project }}"
project: "{{ project }}"
register: Check_keypair_status
- name: " AWS Infra - Copying the private Key Of {{ project }} keypair to local PC"
when: Check_keypair_status.changed == true
copy:
content: "{{ Check_keypair_status.key.private_key}}"
dest: "{{ project }}.pem"
mode: 0400
- name: " AWS Infra - Creating webserver security group"
amazon.aws.ec2_group:
name: "{{ project }}-webserver"
description: "allows 80,443 from all"
region: "{{ region }}"
rules:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 443
to_port: 443
cidr_ip: 0.0.0.0/0
tags:
Name: "{{ project }}-webserver"
project: "{{ project }}"
register: webserver
- name: " AWS Infra - Creating another remote security group"
ec2_group:
name: "{{ project }}-remote"
description: "allows 22 from all"
region: "{{ region }}"
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
tags:
Name: "{{ project }}-remote-sg"
project: "{{ project }}"
register: remote
- name: " AWS Infra - Creating Ec2 Instance For Webserver"
ec2:
region: "{{ region }}"
key_name: "{{ Check_keypair_status.key.name}}"
instance_type: "{{ instance_type }}"
image: "{{ instance_ami }}"
wait: yes
group_id:
- "{{ webserver.group_id }}"
- "{{ remote.group_id }}"
instance_tags:
Name: "{{ project }}-webserver"
project: "{{ project }}"
count_tag:
Name: "{{ project }}-webserver"
exact_count: 2