# Unable to pass ec2 variable from one ansible host to another

**URL:** <https://forum.ansible.com/t/unable-to-pass-ec2-variable-from-one-ansible-host-to-another/22372>\
**Category:** Ansible Project\
**Created:** [August 24, 2016, 5:46pm UTC](https://forum.ansible.com/t/unable-to-pass-ec2-variable-from-one-ansible-host-to-another/22372 "2016-08-24T17:46:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepak.dimri2016](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@deepak.dimri2016](https://forum.ansible.com/u/deepak.dimri2016)\
**Post date:** [August 24, 2016, 5:46pm UTC](https://forum.ansible.com/t/unable-to-pass-ec2-variable-from-one-ansible-host-to-another/22372/1 "2016-08-24T17:46:49Z")

</div>

I want to pass “private\_dns\_name” of my newly created ec2 instances to some other host in my ansible play book. I have tried using set\_fact module to define the variable but no luck! This is ansible playbook entries for host1

`Enter code here...`

```auto
- name: new EC2 instance
   hosts: host1   
  tasks:
    - name: Launch the new EC2 Instance
      ec2:
       aws_access_key: "{{ aws_id }}"
       aws_secret_key: "{{ aws_key }}"
       group_id: "{{ security_group_id }}"
       instance_type: "{{ instance_type }}"
       image: "{{ image }}"
       key_name: "{{ ssh_keyname }}"
       wait: yes
       wait_timeout: 900
       region: "{{ region }}"
       count: 1
       instance_tags:
         Name: Prod-Engineering
      register: ec2
    - name: Register public DNS fact
      set_fact: public_dns= "{{ item.private_dns_name }}"
      with_items: ec2.instances  

```

```auto
    - debug: var=hostvars

```
