Skip to content

Commit

Permalink
aws_ec2: fix populating SSM inventory for multiple hosts
Browse files Browse the repository at this point in the history
The function `_get_ssm_information()` returns dicts with one object.
Multiple results cannot be concatenated using `d.update()`, since it
will keep overwriting the object.
Concatenate the nested lists instead.
  • Loading branch information
r2bit committed Sep 4, 2024
1 parent 26d7243 commit c7ead34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/2227-fix-ssm-inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- aws_ec2 - fix SSM inventory collection for multiple (>40) hosts (https://github.com/ansible-collections/amazon.aws/pull/2227).
8 changes: 4 additions & 4 deletions plugins/inventory/aws_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,17 +670,17 @@ def _add_ssm_information(self, connection, instances):
break

def _get_multiple_ssm_inventories(self, connection, instance_ids):
result = {}
result = []
# SSM inventory filters Values list can contain a maximum of 40 items so we need to retrieve 40 at a time
# https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_InventoryFilter.html
while len(instance_ids) > 40:
filters = [{"Key": "AWS:InstanceInformation.InstanceId", "Values": instance_ids[:40]}]
result.update(_get_ssm_information(connection, filters))
result.extend(_get_ssm_information(connection, filters).get("Entities", []))
instance_ids = instance_ids[40:]
if instance_ids:
filters = [{"Key": "AWS:InstanceInformation.InstanceId", "Values": instance_ids}]
result.update(_get_ssm_information(connection, filters))
return result
result.extend(_get_ssm_information(connection, filters).get("Entities", []))
return {"Entities": result}

def _populate(
self,
Expand Down

0 comments on commit c7ead34

Please sign in to comment.