From c00507bef8ce684db904ef323259758061c821b2 Mon Sep 17 00:00:00 2001 From: Matt Anderson Date: Mon, 10 Apr 2017 11:17:09 -0400 Subject: [PATCH] Allocate an EIP in AWS based on pc-0's PR https://github.com/trailofbits/algo/pull/343 --- roles/cloud-ec2/tasks/main.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/roles/cloud-ec2/tasks/main.yml b/roles/cloud-ec2/tasks/main.yml index be0b0d4e..47e84e94 100644 --- a/roles/cloud-ec2/tasks/main.yml +++ b/roles/cloud-ec2/tasks/main.yml @@ -104,9 +104,20 @@ instance_initiated_shutdown_behavior: terminate register: ec2 +- name: Allocate an EIP for the instances + ec2_eip: + aws_access_key: "{{ aws_access_key | default(lookup('env','AWS_ACCESS_KEY_ID'))}}" + aws_secret_key: "{{ aws_secret_key | default(lookup('env','AWS_SECRET_ACCESS_KEY'))}}" + region: "{{ region }}" + release_on_disassociation: yes + reuse_existing_ip_allowed: yes + in_vpc: yes + device_id: "{{ ec2.tagged_instances[0].id }}" + register: eip + - name: Add new instance to host group add_host: - hostname: "{{ item.public_ip }}" + hostname: "{{ eip.public_ip }}" groupname: vpn-host ansible_ssh_user: ubuntu ansible_python_interpreter: "/usr/bin/python2.7" @@ -116,7 +127,7 @@ with_items: "{{ ec2.tagged_instances }}" - set_fact: - cloud_instance_ip: "{{ ec2.tagged_instances[0].public_ip }}" + cloud_instance_ip: "{{ eip.public_ip }}" - name: Get EC2 instances ec2_remote_facts: