Store ec2 instance IP using ansible playbook

0 votes
I've created a few instances, now I need to store their IP's. How do I write a playbook get and save their IP's?
Mar 25, 2019 in Ansible by Himanshu
1,029 views

1 answer to this question.

0 votes

Hey @Himanshu, you can use something like this:

- name: Store EC2 instance IPs to provision against
  add_host:
    hostname: "{{ item.public_ip }}"
    groupname: ec2_instance_ips
  with_items: "{{ ec2_instances.tagged_instances }}"

Let me know if it helps :)

answered Mar 25, 2019 by Yesha
hostname will get stored in /etc/ansible/hosts file under the groupname: ec2_instance_ips ?

It depends on the path you have given. You can set your path as /etc/ansible/hosts.

Related Questions In Ansible

0 votes
1 answer

Ansible playbook to automate security configurations of an EC2 instance

Hey @Kiara, your indentation is very wrong. ...READ MORE

answered Jan 23, 2019 in Ansible by Harsh
121 views
0 votes
1 answer

devops , how to create user using ansible playbook

root doesn't need a password to switch ...READ MORE

answered Jul 16, 2018 in Ansible by Kalgi
• 2,620 points
196 views
0 votes
1 answer

ansible playbook: using multiple variables in loops

Use an indexed hostname, and then define ...READ MORE

answered Jul 16, 2018 in Ansible by DareDev
• 6,850 points
9,715 views
0 votes
1 answer

Execute a command using ansible playbook

Hey @Reshma, You can use the URI ...READ MORE

answered Jan 17, 2019 in Ansible by Sameer
1,490 views
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 57,550 points
654 views
+13 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,420 points
596 views
0 votes
1 answer

How do I wget a file from web server using shell in the ansible playbook

Hey Ayaan, you could probably use this ...READ MORE

answered Jan 24, 2019 in Ansible by Anushri
1,380 views
0 votes
1 answer

Create directories and download files in Ansible using Ansible playbook

Hey @Yash,  you could either use file module ...READ MORE

answered Jan 24, 2019 in Ansible by Cerdin
2,112 views