From 6a80b01340478e90496c01aa1dfbc157e0533bd8 Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Fri, 24 Jun 2016 09:08:26 +0200 Subject: [PATCH] Allow the definition of the IP when creating a new host --- tasks/ec2/inithost.yml | 30 +++++++++++++++++------------- tasks/ec2/inithostip.yml | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 tasks/ec2/inithostip.yml diff --git a/tasks/ec2/inithost.yml b/tasks/ec2/inithost.yml index 46ea5fb..624bcda 100644 --- a/tasks/ec2/inithost.yml +++ b/tasks/ec2/inithost.yml @@ -26,18 +26,22 @@ state: running wait: yes -- name: "Add new instance(s) to the inventory" - add_host: - hostname="{{ host }}" - static_ipv4="{{ item.public_ip }}" - groups="{{ initgroups }}" - with_items: '{{ ec2.instances }}' +- block: + + - name: "Associate an elastic IP with the new instance" + ec2_eip: + device_id: "{{ item }}" + public_ip: '{{ inithostip }}' + region: "{{ ec2_region }}" + state: present + with_items: '{{ ec2.instance_ids }}' + + - include: inithostip.yml hostip='{{ inithostip }}' + + when: inithostip is defined -- name: "Waiting for SSH service becoming available" - wait_for: - host="{{ item.public_ip }}" - port=22 - delay=10 - timeout=120 - state=present +- include: inithostip.yml hostip='{{ ec2instance.public_ip }}' with_items: '{{ ec2.instances }}' + loop_control: + loop_var: ec2instance + when: inithostip is not defined diff --git a/tasks/ec2/inithostip.yml b/tasks/ec2/inithostip.yml new file mode 100644 index 0000000..7e57143 --- /dev/null +++ b/tasks/ec2/inithostip.yml @@ -0,0 +1,16 @@ +--- +# file: ec2/inithostip.yml + +- name: "Add new instance(s) to the inventory" + add_host: + hostname="{{ host }}" + static_ipv4="{{ hostip }}" + groups="{{ initgroups }}" + +- name: "Waiting for SSH service becoming available" + wait_for: + host="{{ hostip }}" + port=22 + delay=10 + timeout=120 + state=present -- GitLab