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_scheduled_cancel.yml
64 lines (55 loc) · 1.87 KB
/
pause_scheduled_cancel.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
---
# #####################################################################
# Cancel Scheduled Pause
# #####################################################################
- hosts: tag_role_jumphost:&tag_user_{{ user }}
gather_facts: false
tasks:
- debug:
msg:
- "# #####################################################################"
- "# Only Implemented for Linux Instances on AWS yet"
- "# #####################################################################"
- 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"
- hosts: tag_role_jumphost:tag_role_k8smaster:tag_role_k8sworker:tag_role_linuxep:&tag_user_{{ user }}
gather_facts: false
become: yes
vars:
shutdown_delay: 2
tasks:
- name: Include vars
include: site_vars.yml
- 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"
when: type == "aws"
- name: GCP
block:
- name: Query Instance State
set_fact:
gcp_state: "{{ hostvars[inventory_hostname]['status'] }}"
- name: Send Shutdown Command to Linux Instance
at:
command: shutdown -h now
state: absent
when:
- gcp_state == "RUNNING"
when: type == "gcp"