-
Notifications
You must be signed in to change notification settings - Fork 4
/
ec2.yml
85 lines (80 loc) · 2.08 KB
/
ec2.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
85
---
- hosts: local
connection: local
gather_facts: False
vars_files:
- aws-vars.yml
- aws_keys.yml
tasks:
- name : Create SG
ec2_group:
name: "{{ security_group }}"
description: ec2 group for ansible host
region: "{{ region }}"
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
rules_egress:
- proto: all
cidr_ip: 0.0.0.0/0
state: present
- name: Launch EC2 Instance
ec2:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
wait: true
keypair: "{{ keypair }}"
region: "{{ region}}"
count: 1
register: ec2
- name: Add ip to hosts
add_host:
name: "{{ item.public_ip }}"
groups: appservers
with_items: "{{ ec2.instances }}"
- name: Add tag to Instance
ec2_tag:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
resource: "{{ item.id }}"
region: "{{ region }}"
state: "present"
with_items: "{{ ec2.instances }}"
args:
tags:
Type: appservers
- name: check for avaiablity
wait_for:
host: "{{ item.public_ip }}"
port: 22
state: started
with_items : "{{ ec2.instances }}"
# this will require key file
- hosts: appservers
remote_user: ec2-user
become: yes
tasks:
- name: Install apache
yum:
name: httpd
state: present
- name: start enable httpd
service:
name: httpd
state: started
- name: copy application files
copy:
src: /app-data/pragra-fronend/
dest: /var/www/html/
directory_mode: yes