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