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
/
pause_aws.yml
112 lines (98 loc) · 3.41 KB
/
pause_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
---
# #####################################################################
# Pause MOADSD-NG Environment in AWS
# #####################################################################
- name: Pause 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: Pause instance of Kubernetes master
include_role:
name: environment-aws
vars:
operation: pause_instance
instance_name: "{{ kubernetes_master_instance_name }}"
- name: Pause instance of Kubernetes worker(s)
include_role:
name: environment-aws
vars:
operation: pause_instance
instance_name: "{{ kubernetes_worker_instance_name }}{{ item }}"
with_sequence: count="{{ kubernetes_worker_count }}"
- name: Pause instance of PostgreSQL
include_role:
name: environment-aws
vars:
operation: pause_instance
instance_name: "{{ postgresql_instance_name }}"
- name: Pause instance of Deep Security Manager
include_role:
name: environment-aws
vars:
operation: pause_instance
instance_name: "{{ deepsecurity_instance_name }}"
- name: Pause linux endpoint instances
include_role:
name: environment-aws
vars:
operation: pause_instance
instance_name: "{{ linuxep_instance_name }}{{ item }}"
with_sequence: count="{{ linuxep_instance_count }}"
- name: Pause windows endpoint instances
include_role:
name: environment-aws
vars:
operation: pause_instance
instance_name: "{{ windowsep_instance_name }}{{ item }}"
with_sequence: count="{{ windowsep_instance_count }}"
- name: Pause jumphost
include_role:
name: environment-aws
vars:
operation: pause_instance
instance_name: "{{ jumphost_instance_name }}"
- name: Query VPC id
ec2_vpc_net_info:
region: "{{ aws_region }}"
filters:
"tag:Name": "{{ moadsd_ng_prefix }}-vpc"
"tag:project": "{{ moadsd_ng_prefix }}"
"tag:user": "{{ moadsd_ng_user }}"
register: ec2_vpc_net_result
- name: Query Public Subnet id
ec2_vpc_subnet_info:
region: "{{ aws_region }}"
filters:
"tag:Name": "{{ moadsd_ng_prefix }}-public-subnet"
"tag:project": "{{ moadsd_ng_prefix }}"
"tag:user": "{{ moadsd_ng_user }}"
register: public_subnet_result
- name: Query NAT Gateway id
ec2_vpc_nat_gateway_info:
region: "{{ aws_region }}"
filters:
subnet-id: "{{ public_subnet_result.subnets[0].subnet_id }}"
register: nat_gateway_result
when: public_subnet_result.subnets
- name: Terminate NAT Gateway and wait for deleted status.
ec2_vpc_nat_gateway:
state: absent
nat_gateway_id: "{{ item.nat_gateway_id }}"
wait: yes
wait_timeout: 500
release_eip: yes
region: "{{ aws_region }}"
loop: "{{ nat_gateway_result.result }}"
when: nat_gateway_result is not skipped