From ae45c1295a2eb681be8311c8e02d83cfb406bea8 Mon Sep 17 00:00:00 2001 From: Jack Ivanov Date: Thu, 4 May 2017 14:33:31 +0200 Subject: [PATCH] move to Elastic IP (#512) --- roles/cloud-ec2/tasks/main.yml | 4 ++-- roles/cloud-ec2/templates/stack.yml.j2 | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/roles/cloud-ec2/tasks/main.yml b/roles/cloud-ec2/tasks/main.yml index 6c397a52..e32e70a5 100644 --- a/roles/cloud-ec2/tasks/main.yml +++ b/roles/cloud-ec2/tasks/main.yml @@ -26,7 +26,7 @@ - name: Add new instance to host group add_host: - hostname: "{{ stack.stack_outputs.PublicIP }}" + hostname: "{{ stack.stack_outputs.ElasticIP }}" groupname: vpn-host ansible_ssh_user: ubuntu ansible_python_interpreter: "/usr/bin/python2.7" @@ -35,7 +35,7 @@ ipv6_support: yes - set_fact: - cloud_instance_ip: "{{ stack.stack_outputs.PublicIP }}" + cloud_instance_ip: "{{ stack.stack_outputs.ElasticIP }}" - name: Get EC2 instances ec2_remote_facts: diff --git a/roles/cloud-ec2/templates/stack.yml.j2 b/roles/cloud-ec2/templates/stack.yml.j2 index 1678413b..8d9cca20 100644 --- a/roles/cloud-ec2/templates/stack.yml.j2 +++ b/roles/cloud-ec2/templates/stack.yml.j2 @@ -36,7 +36,7 @@ Resources: Type: AWS::EC2::Subnet Properties: CidrBlock: {{ ec2_vpc_nets.subnet_cidr }} - MapPublicIpOnLaunch: true + MapPublicIpOnLaunch: false Tags: - Key: Environment Value: Algo @@ -184,9 +184,13 @@ Resources: - Key: Environment Value: Algo -Outputs: - PublicIP: - Value: - Fn::GetAtt: + ElasticIP: + Type: AWS::EC2::EIP + Properties: + InstanceId: !Ref EC2Instance + DependsOn: - EC2Instance - - PublicIp + +Outputs: + ElasticIP: + Value: !Ref ElasticIP