diff --git a/roles/cloud-ec2/tasks/main.yml b/roles/cloud-ec2/tasks/main.yml index 6c397a5..e32e70a 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 1678413..8d9cca2 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