# Ec2 dynamic inventory, sorting by something else than InstanceId?

**URL:** <https://forum.ansible.com/t/ec2-dynamic-inventory-sorting-by-something-else-than-instanceid/43695>\
**Category:** Get Help\
**Tags:** aws\
**Created:** [July 2, 2025, 3:00pm UTC](https://forum.ansible.com/t/ec2-dynamic-inventory-sorting-by-something-else-than-instanceid/43695 "2025-07-02T15:00:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [July 2, 2025, 3:00pm UTC](https://forum.ansible.com/t/ec2-dynamic-inventory-sorting-by-something-else-than-instanceid/43695/1 "2025-07-02T15:00:24Z")

</div>

Hii, I’m trying to move away from the old `ec2.py` dynamic inventory to the current (supported) [amazon.aws.aws\_ec2 inventory – EC2 inventory source — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/collections/amazon/aws/aws_ec2_inventory.html).

I have everything working - execpt one thing. The current inventory script has hard coded sorting of the found instances by `InstanceId`: [amazon.aws/plugins/inventory/aws\_ec2.py at main · ansible-collections/amazon.aws · GitHub](https://github.com/ansible-collections/amazon.aws/blob/main/plugins/inventory/aws_ec2.py#L780)

Our old `ec2.py` had a local patch, to allow sorting by the value of the `Name` tag (or other tags).

Before I try to create a similar patch for the current plugin, would such a feature be acceptable?

thx

---

<div class="post-metadata">

**Author:** ![markuman](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@markuman](https://forum.ansible.com/u/markuman)\
**Post date:** [July 2, 2025, 8:17pm UTC](https://forum.ansible.com/t/ec2-dynamic-inventory-sorting-by-something-else-than-instanceid/43695/2 "2025-07-02T20:17:08Z")

</div>

Yes, amazon.aws also accept community contributions [GitHub - ansible-collections/amazon.aws: Ansible Collection for Amazon AWS](https://github.com/ansible-collections/amazon.aws)

What’s the usecase for sorting instances in the inventory?

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [July 3, 2025, 7:00am UTC](https://forum.ansible.com/t/ec2-dynamic-inventory-sorting-by-something-else-than-instanceid/43695/3 "2025-07-03T07:00:45Z")

</div>

> [@markuman](#):
>
> hat’s the usecase for sorting instances in the inventory?

See [aws\_ec2\_inventory: Allow sorting by something else than InstanceId · Issue #2672 · ansible-collections/amazon.aws · GitHub](https://github.com/ansible-collections/amazon.aws/issues/2672).  
I closed it again as there is something already that does what we need 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 2, 2025, 7:01am UTC](https://forum.ansible.com/t/ec2-dynamic-inventory-sorting-by-something-else-than-instanceid/43695/4 "2025-08-02T07:01:28Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
