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...

- 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  

    - debug: var=hostvars

- hosts: host2
   become: yes
   tasks:
    - command: ipa host-add "{{ hostvars['host1']['public_dns'] }}" 
--password=xxxxx

 But i am getting "'ansible.vars.hostvars.HostVars object' has no 
attribute" error. Every try of mine is failing and i am stuck with this 
issue. Would really appreciate if some one can help with this. I am using 
Ansible 2.1.1.0

Thanks, Deepak


-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/28ac3ff9-8679-4051-b38d-dd7bbcb72c24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to