amazon ec2 - how to get ec2 instances public dns name by ansible playbook -
i playing ansible automate ec2 instances. created ec2 instance , m trying public dns name via ec2_remote_facts module. giving variable not defined in output.
playbook: - hosts: localhost connection: local tasks: - name: ec2 instance facts ec2_remote_facts: region: ap-southeast-2 filters: instance-state-name: running register: ec2 - debug: var=ec2.instances.public_name output:play [localhost] *************************************************************** task [setup] ******************************************************************* ok: [localhost] task [create ec2 instance] ***************************************************** ok: [localhost] task [debug] ******************************************************************* ok: [localhost] => { "ec2.instances.public_name": "variable not defined!" } play recap ********************************************************************* localhost : ok=3 changed=0 unreachable=0 failed=0 output ec2.instances. ok: [localhost] => { "ec2.instances": [ { "ami_launch_index": "0", "architecture": "x86_64", "client_token": "", "ebs_optimized": false, "groups": [ { "id": "sg-6c016a08", "name": "default" } ], "hypervisor": "xen", "id": "i-915b1813", "image_id": "ami-fedafc9d", "instance_profile": null, "interfaces": [ { "id": "eni-96de4acf", "mac_address": "0a:14:ac:64:c4:13" } ], "kernel": null, "key_name": "ansible.key", "launch_time": "2016-08-29t07:32:10.000z", "monitoring_state": "disabled", "persistent": false, "placement": { "tenancy": "default", "zone": "ap-southeast-2c" }, "private_dns_name": "ip-xx-xx-xx-107.ap-southeast-2.compute.internal", "private_ip_address": "xx.xx.xx.107", "public_dns_name": "ec2-xx-xxx-xx-80.ap-southeast-2.compute.amazonaws.com", "ramdisk": null, "region": "ap-southeast-2", "requester_id": null, "root_device_type": "ebs", "source_destination_check": "true", "spot_instance_request_id": null, "state": "running", "tags": { "name": "demo" }, "virtualization_type": "hvm", "vpc_id": "vpc-abcaf4ce" } ] }
what m missing here?
thanks
benjo
if closely ec2.instances
may note that:
- it list, either access items index
ec2.instances[0]
or iterate on themwith_items:
structure. - there no
public_name
attribute,public_dns_name
.
Comments
Post a Comment