print public dns name of ec2 instance

Hi,

I am testing to print ec2 instance public dns names by ansible.

  • hosts: localhost
    connection: local

tasks:

  • name: get instance public dns name
    ec2_remote_facts:
    region: ap-southeast-2
    filters:
    instance-state-name: running
    register: ec2

  • debug: var=ec2.instances.public_dns_name

but i got " “ec2.instances.public_dns_name”: “VARIABLE IS NOT DEFINED!” .

where i m doing mistake?

Thanks
Benjo