-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.yml
104 lines (90 loc) · 2.62 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
- name: "Rolling Update For ASG"
hosts: localhost
vars_files:
- app.vars
tasks:
- name: "Installing pip"
yum:
name: pip
state: present
- name: "Installing boto3"
pip:
name: boto3
state: present
- name: "Fetching Ec2 ASG Details"
ec2_instance_info:
region: "{{region}}"
filters:
"tag:aws:autoscaling:groupName": "{{tag_name}}"
instance-state-name: ["running"]
register: asg_instances
- debug: var=asg_instances
- name: "Dynamic Inventory For Autosclaing Ec2"
add_host:
name: "{{item.public_ip_address}}"
groups: "asg"
ansible_host: "{{item.public_ip_address}}"
ansible_port: 22
ansible_user: "ec2-user"
ansible_ssh_private_key_file: "{{private_key}}"
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
with_items:
- "{{asg_instances.instances}}"
- name: "Deploying Website From GitHub to ASG"
become: true
hosts: asg
gather_facts: false
serial: 1
vars_files:
- app.vars
tasks:
- name: "Installing the Git Packages"
yum:
name:
- httpd
- git
state: latest
- name: "Creating the Clone Directory"
file:
path: "{{clonDir}}"
state: directory
- name: "Cloning the Git Repository"
git:
repo: "{{gitRepository}}"
dest: "{{clonDir}}"
register: clone_status
- name: "Disabling Health Check"
when: clone_status.changed
file:
path: /var/www/html/health.txt
state: file
mode: 000
- name: "Offloading Ec2 Instance"
when: clone_status.changed
pause:
seconds: "{{health_time}}"
prompt: "Please Hold on off loading Is going On"
- name: "Copying the contents from the Clone Directory to Ec2 Instances"
when: clone_status.changed
copy:
src: "{{clonDir}}"
dest: /var/www/html/
remote_src: true
- name: "Restarting/Enabling httpd"
when: clone_status.changed
service:
name: httpd
state: restarted
enabled: true
- name: "Enabling the Health Check"
when: clone_status.changed
file:
path: /var/www/html/health.txt
state: file
mode: 0644
- name: "Loading Back the Ec2 instance"
when: clone_status.changed
pause:
seconds: "{{health_time}}"
prompt: "Please hold on Loading back the Ec2 Instance"