---
|
- 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 }}"
|
# 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 }}"
|
# 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: Print status information to a file
|
copy:
|
dest: "{{ output_dir }}/status.txt"
|
content: |-
|
{{ "%-60s" | format('Instance') }} State Type
|
----------------------------------------------------------------
|
{% for instance in r_instances.instances %}
|
{{ "%-60s" | format(instance.tags.Name) }} {{ "%-10s" | format(instance.state.name) }} {{ instance.instance_type }}
|
{% endfor %}
|