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