Hi Mark.
This is the typical outcome of AWS’ flow. When you assign an EIP to an instance, you can forget about the public dns and public ip entries. they are updated according to the EIP.
As a tip, I am registering the output of the ec2_eip module and use that instead of querying the ec2 module’s results. One can also (supposedly) use the ec2_facts module or just output the added EIP to a file with the lineinfile module and read it from there or use the in-memory inventory with add_host.
FYI, here’s what ec2_facts gets:
`
[dvaida@scat ansible-aws]$ ansible -i host all --user=admin --private-key=ansible-ec2.pem -m ec2_facts
The authenticity of host ‘54.76.235.184 (54.76.235.184)’ can’t be established.
ECDSA key fingerprint is ec:11:61:76:a0:28:b5:83:10:a7:3c:b5:d8:02:71:bb.
Are you sure you want to continue connecting (yes/no)? yes
54.76.235.184 | success >> {
“ansible_facts”: {
“ansible_ec2_ami_id”: “ami-630fcb14”,
“ansible_ec2_ami_launch_index”: “0”,
“ansible_ec2_ami_manifest_path”: “(unknown)”,
“ansible_ec2_block_device_mapping_ami”: “/dev/sda”,
“ansible_ec2_block_device_mapping_root”: “/dev/sda”,
“ansible_ec2_hostname”: “ip-10-0-0-8.eu-west-1.compute.internal”,
“ansible_ec2_instance_action”: “none”,
“ansible_ec2_instance_id”: “i-9edd71dd”,
“ansible_ec2_instance_type”: “c3.2xlarge”,
“ansible_ec2_kernel_id”: “aki-52a34525”,
“ansible_ec2_local_hostname”: “ip-10-0-0-8.eu-west-1.compute.internal”,
“ansible_ec2_local_ipv4”: “10.0.0.8”,
“ansible_ec2_mac”: “06:31:2e:4a:82:e2”,
“ansible_ec2_metrics_vhostmd”: “<?xml version=\"1.0\" encoding=\"UTF-8\"?>”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_device_number”: “0”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_interface_id”: “eni-4fb93f38”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_ipv4_associations_54.76.235.184”: “10.0.0.8”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_local_hostname”: “ip-10-0-0-8.eu-west-1.compute.internal”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_local_ipv4s”: “10.0.0.8”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_mac”: “06:31:2e:4a:82:e2”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_owner_id”: “785351690827”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_public_hostname”: “ec2-54-76-235-184.eu-west-1.compute.amazonaws.com”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_public_ipv4s”: “54.76.235.184”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_security_group_ids”: “sg-0b10de6e”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_security_groups”: “allinone”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_subnet_id”: “subnet-ddca27aa”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_subnet_ipv4_cidr_block”: “10.0.0.0/24”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_vpc_id”: “vpc-9037d9f5”,
“ansible_ec2_network_interfaces_macs_06_31_2e_4a_82_e2_vpc_ipv4_cidr_block”: “10.0.0.0/16”,
“ansible_ec2_placement_availability_zone”: “eu-west-1a”,
“ansible_ec2_placement_region”: “eu-west-1”,
“ansible_ec2_profile”: “default-paravirtual”,
“ansible_ec2_public_hostname”: “ec2-54-76-235-184.eu-west-1.compute.amazonaws.com”,
“ansible_ec2_public_ipv4”: “54.76.235.184”,
“ansible_ec2_public_key”: “ssh-rsa XXX ansible-ec2\n”,
“ansible_ec2_reservation_id”: “r-a5fe14e6”,
“ansible_ec2_security_groups”: “allinone”,
“ansible_ec2_services_domain”: “amazonaws.com”,
“ansible_ec2_user_data”: null
},
“changed”: false
}
`
I believe this module should get better documentation.
Hope this helps you!