# How to get all the instances per VPC and get security group of each instance for a particular zone.

**URL:** <https://forum.ansible.com/t/how-to-get-all-the-instances-per-vpc-and-get-security-group-of-each-instance-for-a-particular-zone/25401>\
**Category:** Ansible Project\
**Created:** [September 4, 2017, 10:12am UTC](https://forum.ansible.com/t/how-to-get-all-the-instances-per-vpc-and-get-security-group-of-each-instance-for-a-particular-zone/25401 "2017-09-04T10:12:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nirjhar\_Banik](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@Nirjhar\_Banik](https://forum.ansible.com/u/Nirjhar_Banik)\
**Post date:** [September 4, 2017, 10:12am UTC](https://forum.ansible.com/t/how-to-get-all-the-instances-per-vpc-and-get-security-group-of-each-instance-for-a-particular-zone/25401/1 "2017-09-04T10:12:03Z")

</div>

I’m trying to pull all the information of all the instances per VPC and get security group of each instance for a particular zone. I am using **ec2\_vpc** (it is deprecated) module to get the information about an existing VPC but from reading the docs, I’m not completely sure this is possible since all the docs and examples are assuming you are either creating a VPC or deleting one.

Can anyone help me with a solution of how to get the full list of ec2 instance info for a particular region? Thanks!

---

<div class="post-metadata">

**Author:** ![Pshem\_Kowalczyk](https://avatars.discourse-cdn.com/v4/letter/p/e480ec/32.png) [@Pshem\_Kowalczyk](https://forum.ansible.com/u/Pshem_Kowalczyk)\
**Post date:** [September 4, 2017, 10:42am UTC](https://forum.ansible.com/t/how-to-get-all-the-instances-per-vpc-and-get-security-group-of-each-instance-for-a-particular-zone/25401/2 "2017-09-04T10:42:51Z")

</div>

You need a number of separate steps:

1. Get VPC id (ec2\_vpc\_net\_facts)
2. Get list of instances in that VPC using vpc-id as a filter (ec2\_remote\_facts)
3. Get the list of ENIs for each of those EC2 instances (ec2\_eni\_facts)

The last module will return information about security groups used by the ENIs.

kind regards  
Pshem

---

<div class="post-metadata">

**Author:** ![Nirjhar\_Banik](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@Nirjhar\_Banik](https://forum.ansible.com/u/Nirjhar_Banik)\
**Post date:** [September 5, 2017, 4:08pm UTC](https://forum.ansible.com/t/how-to-get-all-the-instances-per-vpc-and-get-security-group-of-each-instance-for-a-particular-zone/25401/3 "2017-09-05T16:08:02Z")

</div>

Thanks Pshem, worked for me!

Cheers!  
Nirjhar
