diff --git a/changelogs/fragments/2227-fix-ssm-inventory.yml b/changelogs/fragments/2227-fix-ssm-inventory.yml new file mode 100644 index 0000000000..dc1e98adfe --- /dev/null +++ b/changelogs/fragments/2227-fix-ssm-inventory.yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- aws_ec2 - fix SSM inventory collection for multiple (>40) hosts (https://github.com/ansible-collections/amazon.aws/pull/2227). diff --git a/plugins/inventory/aws_ec2.py b/plugins/inventory/aws_ec2.py index bf0bc50b12..880919772d 100644 --- a/plugins/inventory/aws_ec2.py +++ b/plugins/inventory/aws_ec2.py @@ -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,