# Separate Ips Dinamically by Groups AWS

**URL:** <https://forum.ansible.com/t/separate-ips-dinamically-by-groups-aws/4016>\
**Category:** Get Help\
**Tags:** aws, collections\
**Created:** [February 23, 2024, 3:17pm UTC](https://forum.ansible.com/t/separate-ips-dinamically-by-groups-aws/4016 "2024-02-23T15:17:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dedeboy](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dedeboy/32/2062_2.png) [@dedeboy](https://forum.ansible.com/u/dedeboy)\
**Post date:** [February 23, 2024, 3:17pm UTC](https://forum.ansible.com/t/separate-ips-dinamically-by-groups-aws/4016/1 "2024-02-23T15:17:10Z")

</div>

I need a help about a problem about creation groups. I created a playbook AWS in which I create the instances and I have a file called host. My objective is when AWS creates the instances I want, separate the IPs for groups example below. I don’t know how I will to do in this subject.

Example

[GroupA]

Ip Ansible-01

[Group B]

Ip Ansible-02

Ip Ansible-03

Thanks in advance

Best Regards

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [February 23, 2024, 6:37pm UTC](https://forum.ansible.com/t/separate-ips-dinamically-by-groups-aws/4016/2 "2024-02-23T18:37:47Z")

</div>

I’m not sure about separating into groups by IP, but would you be able to use the [amazon.aws.aws\_ec2](https://docs.ansible.com/ansible/latest/collections/amazon/aws/aws_ec2_inventory.html#ansible-collections-amazon-aws-aws-ec2-inventory) inventory plugin to make keyed\_groups by some value? There are several examples of keyed\_groups in the documentation that may help you.

---

<div class="post-metadata">

**Author:** ![valkiriaaquatica](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/valkiriaaquatica/32/1308_2.png) [@valkiriaaquatica](https://forum.ansible.com/u/valkiriaaquatica)\
**Post date:** [February 24, 2024, 4:22pm UTC](https://forum.ansible.com/t/separate-ips-dinamically-by-groups-aws/4016/3 "2024-02-24T16:22:09Z")

</div>

Hello Dedeboy,  
what you can do is to add a tag to each machine with the ip of the machine, and then in the aws dynamic inventory that you use in kayed\_groups, take the tag value and it will form groups by ip.  
In the dynamic inventory you could put something like this:  
kayes\_groups:  
key: ip\_  
tag  
and this will take the tag from each machine’s own variable, creating groups by its IP.
