Separate Ips Dinamically by Groups AWS

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

I’m not sure about separating into groups by IP, but would you be able to use the amazon.aws.aws_ec2 inventory plugin to make keyed_groups by some value? There are several examples of keyed_groups in the documentation that may help you.

1 Like

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.