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,305 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 in Ansible by MD
• 79,930 points
137 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 in Ansible by MD
• 79,930 points
42 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 23, 2019 in Ansible by Harsh
146 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 in Ansible by MD
• 79,930 points
246 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
• 57,700 points
917 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
809 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,782 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,651 views