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.0Thanks, Deepak