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
3,101 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

How to launch an EC2 instance using Ansible Playbook?

Hi@akhtar, Ansible has one module named ec2. This ...READ MORE

answered Aug 12, 2020 in Ansible by MD
• 95,440 points
1,719 views
0 votes
1 answer

How to do SSH in EC2 instance using Ansible Playbook?

Hi@akhtar, To configure your inventory dynamically you need ...READ MORE

answered Sep 21, 2020 in Ansible by MD
• 95,440 points
2,166 views
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 24, 2019 in Ansible by Harsh
582 views
0 votes
1 answer

Is it possible to start ec2 Windows machine and run windows command using ansible playbook?

Hi@Lakshminarayanan, Yes, you can do that. But after ...READ MORE

answered Aug 14, 2020 in Ansible by MD
• 95,440 points
2,039 views
+2 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
• 58,090 points
2,469 views
+15 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,506 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
3,863 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
5,398 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP