Commit 93004978 by John Jarvis

moving terminationg logic to launch_instance role

parent c4493217
...@@ -3,18 +3,6 @@ ...@@ -3,18 +3,6 @@
connection: local connection: local
gather_facts: False gather_facts: False
pre_tasks: pre_tasks:
- ec2_lookup:
region: "{{ region }}"
tags:
Name: "{{ name_tag }}"
register: tag_lookup
- debug: msg="Too many results returned, not terminating!"
when: tag_lookup.instance_ids|length > 1
- ec2:
state: 'absent'
region: "{{ region }}"
instance_ids: ${tag_lookup.instance_ids}
when: tag_lookup.instance_ids|length == 1
roles: roles:
- role: launch_ec2 - role: launch_ec2
keypair: "{{ keypair }}" keypair: "{{ keypair }}"
...@@ -26,6 +14,7 @@ ...@@ -26,6 +14,7 @@
root_ebs_size: "{{ root_ebs_size }}" root_ebs_size: "{{ root_ebs_size }}"
dns_name: "{{ dns_name }}" dns_name: "{{ dns_name }}"
dns_zone: "{{ dns_zone }}" dns_zone: "{{ dns_zone }}"
terminate_instance: true
- name: Configure instance(s) - name: Configure instance(s)
hosts: launched hosts: launched
......
# Launches an ec2 instance and blocks until the instance is up # Launches an ec2 instance and blocks until the instance is up
# adds it to the host group # adds it to the host group
# Will terminate an instance if one and only one already exists
# with the same name
- name: lookup tags for terminating existing instance
local_action:
module: ec2_lookup
region: "{{ region }}"
tags:
Name: "{{ name_tag }}"
register: tag_lookup
when: terminate_instance == true
- debug: msg="Too many results returned, not terminating!"
when: terminate_instance == true and tag_lookup.instance_ids|length > 1
- name: terminating single instance
local_action:
module: ec2
state: 'absent'
region: "{{ region }}"
instance_ids: ${tag_lookup.instance_ids}
when: terminate_instance == true and tag_lookup.instance_ids|length == 1
- name: launch_ec2 | Launch ec2 instance - name: launch_ec2 | Launch ec2 instance
local_action: local_action:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment