This repository has been archived by the owner on Aug 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
resume_aws.yml
228 lines (202 loc) · 6.77 KB
/
resume_aws.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# - hosts: tag_role_jumphost:&tag_user_{{ user }}
# gather_facts: false
# tasks:
# - name: Get ipaddr of jumphost
# set_fact:
# remote_ip: "{{ inventory_hostname | ipaddr}}"
# - name: Get ipaddr of jumphost
# set_fact:
# remote_ip: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
# when: not remote_ip
# - name: Store external ip address of jumphost
# add_host:
# name: "{{ remote_ip }}"
# groups: "moadsd_ng_jumphost_instance_public"
- name: Resume MOADSD-NG Environment
hosts: localhost
gather_facts: no
connection: local
vars:
tasks:
- name: Check if AWS cloud SDK is installed
command: aws --version
register: aws_installed
changed_when: false
ignore_errors: yes
- fail:
msg: "Please make sure AWS Cloud SDK is installed before executing the role."
when: aws_installed is failed
- name: Include vars
include: site_vars.yml
- name: Recreate AWS VPC
include_role:
name: environment-aws
vars:
operation: create_network
- name: Resume jumphost
include_role:
name: environment-aws
vars:
operation: resume_instance
instance_name: "{{ jumphost_instance_name }}"
- name: Wating for Jumphost and Kubernetes Master to Come up
pause:
minutes: 1
- name: Resume instance of Kubernetes master
include_role:
name: environment-aws
vars:
operation: resume_instance
instance_name: "{{ kubernetes_master_instance_name }}"
- name: Resume instance of Kubernetes worker(s)
include_role:
name: environment-aws
vars:
operation: resume_instance
instance_name: "{{ kubernetes_worker_instance_name }}{{ item }}"
with_sequence: count="{{ kubernetes_worker_count }}"
- name: Resume instance of PostgreSQL
include_role:
name: environment-aws
vars:
operation: resume_instance
instance_name: "{{ postgresql_instance_name }}"
- name: Resume instance of Deep Security Manager
include_role:
name: environment-aws
vars:
operation: resume_instance
instance_name: "{{ deepsecurity_instance_name }}"
- name: Resume linux endpoint instances
include_role:
name: environment-aws
vars:
operation: resume_instance
instance_name: "{{ linuxep_instance_name }}{{ item }}"
with_sequence: count="{{ linuxep_instance_count }}"
- name: Resume windows endpoint instances
include_role:
name: environment-aws
vars:
operation: resume_instance
instance_name: "{{ windowsep_instance_name }}{{ item }}"
with_sequence: count="{{ windowsep_instance_count }}"
- hosts: localhost
gather_facts: false
tasks:
- name: Include vars
include: site_vars.yml
- name: Create Jumphost SSH Command
delegate_to: 127.0.0.1
copy:
dest: "./jumphost"
content: |
ssh ubuntu@{{ jumphost_ip }}
force: yes
owner: ansible
mode: '0700'
- name: Create Master SSH Command
delegate_to: 127.0.0.1
copy:
dest: "./master"
content: |
ssh -o ProxyCommand="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -W %h:%p {{ jumphost_ip }}" ubuntu@{{ k8smaster_ip }} $1
force: yes
owner: ansible
mode: '0700'
- name: Create Copy Master Command
delegate_to: 127.0.0.1
copy:
dest: "./master_copy"
content: |
scp -o ProxyCommand="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -W %h:%p {{ jumphost_ip }}" $1 ubuntu@{{ k8smaster_ip }}:~/$1
force: yes
owner: ansible
mode: '0700'
- name: Create Fetch Master Command
delegate_to: 127.0.0.1
copy:
dest: "./master_fetch"
content: |
scp -o ProxyCommand="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -W %h:%p {{ jumphost_ip }}" ubuntu@{{ k8smaster_ip }}:~/$1 $1
force: yes
owner: ansible
mode: '0700'
- name: Create Cluster Watch Pods Command
delegate_to: 127.0.0.1
copy:
dest: "./cluster_pods"
content: |
watch './master "kubectl get pods --all-namespaces"'
force: yes
owner: ansible
mode: '0700'
- name: Create Cluster Watch Services Command
delegate_to: 127.0.0.1
copy:
dest: "./cluster_services"
content: |
watch './master "kubectl get services --all-namespaces"'
force: yes
owner: ansible
mode: '0700'
- name: Create Cluster Watch Deployments Command
delegate_to: 127.0.0.1
copy:
dest: "./cluster_deployments"
content: |
watch './master "kubectl get deployments --all-namespaces"'
force: yes
owner: ansible
mode: '0700'
- name: Create Cluster Check Command
delegate_to: 127.0.0.1
copy:
dest: "./cluster_check"
content: |
./master 'if [ $(kubectl get deployments --all-namespaces | grep -cw "\([1-9]\)/\1") -eq $(kubectl get deployments --all-namespaces | grep -c "/") ] ; then echo cluster clean ; else echo cluster not clean ; fi'
force: yes
owner: ansible
mode: '0700'
- name: Create Cluster Check Docker Rate Limit
delegate_to: 127.0.0.1
copy:
dest: "./cluster_limits"
content: |
./master 'curl -s --head -H "Authorization: Bearer $(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:ratelimitpreview/test:pull" | jq -r .token)" https://registry-1.docker.io/v2/ratelimitpreview/test/manifests/latest | grep RateLimit'
force: yes
owner: ansible
mode: '0700'
# - hosts: tag_role_jumphost:tag_role_k8smaster:tag_role_k8sworker:tag_role_linuxep:&tag_user_{{ user }}
# gather_facts: false
# become: yes
#
# tasks:
# - name: Include vars
# include: site_vars.yml
#
# - name: Wating for instances to Come up
# pause:
# minutes: 5
#
# - name: AWS
# block:
# - name: Query Instance State
# set_fact:
# ec2_state: "{{ hostvars[inventory_hostname]['ec2_state'] }}"
#
# - name: Cancel Shutdown on Linux Instance
# at:
# command: shutdown -h now
# state: absent
# when:
# - ec2_state == "running"
#
# - name: Send Shutdown Command to Linux Instance
# at:
# command: shutdown -h now
# count: "{{ instance_shutdown_delay }}"
# units: minutes
# when:
# - ec2_state == "running"
# when: type == "aws"