-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathalwaysup_no.yml
40 lines (35 loc) · 1.06 KB
/
alwaysup_no.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
---
- name: ec2 test
hosts: localhost
become: true
vars:
region: us-west-2
wait_for_stop: False
tasks:
- name: Build a list of AlwaysUp:NO instances
ec2_instance_info:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
region: "{{ region }}"
filters:
"tag:AlwaysUp": "NO"
register: alwaysup_no_instances
- name: Log instance_ids
debug:
var: item.instance_id
with_items: "{{ alwaysup_no_instances.instances }}"
- name: set fact instance_ids
set_fact:
instance_ids: "{{ instance_ids|default([]) }} + [ '{{ item.instance_id }}' ]"
with_items: "{{ alwaysup_no_instances.instances }}"
- name: Log instance_ids
debug:
var: instance_ids
- name: Stop the AlwaysUp:NO instances
ec2:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
region: "{{ region }}"
instance_ids: "{{ instance_ids }}"
state: stopped
wait: "{{ wait_for_stop }}"