-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsite.maintenance.aws-stop.yml
67 lines (60 loc) · 1.9 KB
/
site.maintenance.aws-stop.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
- hosts: localhost
connection: local
roles:
- role: cs.aws-region-facts
- role: cs.aws-rds-facts
- role: cs.aws-node-facts
- role: cs.aws-autoscaling-facts
tasks:
- name: Scale down all App Node ASGs
when: stop_asg
block:
- name: Get App Node Auto Scaling Groups
community.aws.ec2_asg_info:
region: "{{ aws_region }}"
tags: "{{ aws_tags_base | combine(aws_tags_role_app) }}"
register: stop_asg_facts
- name: Scale down ASG to zero
ec2_asg:
name: "{{ item.name }}"
region: "{{ aws_region }}"
state: present
desired_capacity: 0
min_size: 0
wait_for_instances: no
with_items: "{{ stop_asgs }}"
vars:
stop_asgs: "{{ stop_asg_facts | json_query('results[].{ name: auto_scaling_group_name }') }}"
- name: Stop standalone EC2 instances
when: stop_ec2
amazon.aws.ec2_instance:
instance_ids: "{{ item.instance_id }}"
region: "{{ aws_region }}"
state: stopped
wait: no
with_items:
- "{{ aws_persistent_node_instance }}"
- "{{ aws_varnish_node_instance }}"
- name: Scale down all App Node ASGs
when: stop_asg
ec2_asg:
name: "{{ item.auto_scaling_group_name }}"
region: "{{ aws_region }}"
state: present
desired_capacity: 0
min_size: 0
wait_for_instances: no
with_items:
- "{{ aws_autoscaling_app }}"
- "{{ aws_autoscaling_app_extra }}"
- name: Stop RDS instance
rds_instance:
state: stopped
region: "{{ aws_region }}"
db_instance_identifier: "{{ aws_rds_instance.db_instance_identifier }}"
when: stop_rds and aws_rds_instance is defined
vars:
stop: yes
stop_ec2: "{{ stop }}"
stop_asg: "{{ stop }}"
stop_rds: "{{ stop }}"