forked from redhat-cop/agnosticd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlifecycle_ec2.yml
More file actions
56 lines (52 loc) · 2.06 KB
/
lifecycle_ec2.yml
File metadata and controls
56 lines (52 loc) · 2.06 KB
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
---
- environment:
AWS_ACCESS_KEY_ID: "{{aws_access_key_id}}"
AWS_SECRET_ACCESS_KEY: "{{aws_secret_access_key}}"
AWS_DEFAULT_REGION: "{{aws_region_final|d(aws_region)}}"
block:
- when: ACTION == 'stop'
name: Stop instances by (guid,env_type) tags
ec2_instance:
state: stopped
wait: no
filters:
"tag:guid": "{{ guid }}"
instance-state-name: running
# TODO: uncomment this after a few weeks
#"tag:env_type": "{{ env_type }}"
- when: ACTION == 'start'
name: Start instances by (guid, env_type) tags
ec2_instance:
state: started
wait: no
filters:
"tag:guid": "{{ guid }}"
instance-state-name: stopped
# TODO: uncomment this after a few weeks
#"tag:env_type": "{{ env_type }}"
- when: ACTION == 'status'
block:
- name: Get EC2 facts using (guid, env_type) tag
ec2_instance_facts:
filters:
"tag:guid": "{{ guid }}"
# TODO: uncomment this after a few weeks
#"tag:env_type": "{{ env_type }}"
register: r_instances
- name: Report status in user info
agnosticd_user_info:
msg: |-
{{ "%-60s %-10s %s" | format("Instance", "State", "Type") }}
----------------------------------------------------------------
{% for instance in r_instances.instances %}
{{ "%-60s %-10s %s" | format(instance.tags.Name, instance.state.name, instance.instance_type) }}
{% endfor %}
- name: Print status information to a file
copy:
dest: "{{ output_dir }}/status.txt"
content: |-
{{ "%-60s %-10s %s" | format("Instance", "State", "Type") }}
----------------------------------------------------------------
{% for instance in r_instances.instances %}
{{ "%-60s %-10s %s" | format(instance.tags.Name, instance.state.name, instance.instance_type) }}
{% endfor %}