-
Notifications
You must be signed in to change notification settings - Fork 5
/
sleep_schedule_off.yaml
34 lines (30 loc) · 1.02 KB
/
sleep_schedule_off.yaml
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
---
- name: this playbook will turn off ec2 instances with sleep_schedule tag
hosts: localhost
gather_facts: false
vars:
ec2_region: "{{ your_region | default('us-east-2') }}"
tasks:
# retrieve instances for VPC 1
- name: grab info
amazon.aws.ec2_instance_info:
region: "{{ ec2_region }}"
filters:
instance-state-name: [ "running" ]
"tag:sleep_schedule": true
register: ec2_node_info
- name: display sleep_schedule devices
debug:
msg: "{{ lookup('template', 'templates/sleep_schedule.j2') }}"
- name: display sleep_schedule devices
set_fact:
shutoff_instances: "{{ lookup('template', 'templates/sleep_schedule_list.j2') }}"
- name: display sleep_schedule devices
debug:
msg: "{{ shutoff_instances }}"
- name: turn off sleepy instances
amazon.aws.ec2_instance:
region: "{{ ec2_region }}"
state: stopped
instance_ids: "{{ shutoff_instances }}"
when: shutoff_instances | length > 0