Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_ec2 use_ssm_inventory fails with a large number of instances #1713

Closed
1 task done
zombrie opened this issue Aug 29, 2023 · 7 comments · Fixed by #1957
Closed
1 task done

aws_ec2 use_ssm_inventory fails with a large number of instances #1713

zombrie opened this issue Aug 29, 2023 · 7 comments · Fixed by #1957
Labels
bug This issue/PR relates to a bug inventory inventory plugin needs_verified Some one might want to take a look at this and reproduce it to confirm plugins plugin (any type) python3

Comments

@zombrie
Copy link

zombrie commented Aug 29, 2023

Summary

After upgrading to version 6.0.0 and enabling use_ssm_inventory, dynamic inventory graphing fails with a warning. Our setup has many instances, and so the list of instance ids is well over the 40 character limit for the aws ssm get-inventory api endpoint.

Issue Type

Bug Report

Component Name

aws_ec2

Ansible Version

ansible --version
ansible [core 2.15.3]

Collection Versions

ansible-galaxy collection list

# /opt/homebrew/lib/python3.11/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    6.0.0  

AWS SDK versions

pip3 show boto boto3 botocore
WARNING: Package(s) not found: boto
Name: boto3
Version: 1.26.152
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Location: /opt/homebrew/lib/python3.11/site-packages
Requires: botocore, jmespath, s3transfer
Required-by: 
---
Name: botocore
Version: 1.29.152
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email: 
License: Apache License 2.0
Location: /opt/homebrew/lib/python3.11/site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer

Configuration

No response

OS / Environment

No response

Steps to Reproduce

inventory/aws_ec2.yml

---
##
# AWS EC2 Inventory
##

# Dynamic AWS inventory: Uses the aws_ec2 plugin to generate a dynamic inventory.
# For more info and examples see:
#  - https://docs.ansible.com/ansible/latest/collections/amazon/aws/docsite/aws_ec2_guide.html
#  - https://docs.ansible.com/ansible/latest/collections/amazon/aws/aws_ec2_inventory.html#id3
#
# Usage:
# - Run `ansible-inventory --graph` to list the available hosts and groups.

# Enable the aws_ec2 plugin
plugin: aws_ec2

# Enables fetching additional EC2 instance information from the AWS Systems Manager (SSM) inventory service into hostvars.
use_ssm_inventory: true

##
# Hosts
##

# This controls how we display hostnames.
hostnames:

  # Using the Hostname tag is more aligned with the legacy static inventory and easier to reference for humans. However using `instance-id` might be more practical in the future with dynamic groups.
  - tag:Hostname

##
# Groups
##

# Generate dynamic groups to run playbooks against.
keyed_groups:
  # Using tags to generate groups. This gives something similar to our legacy static inventory with familiar names to identify instances with.

  # By Application name
  - key: tags.Application
    prefix: App

  # By Environment
  - key: tags.Environment
    prefix: Env


##
# Compose
##

# Compose creates vars from Jinja2 templates but also allows us to set some connection details for the dynamic inventory.
compose:
  # Use SSM Agent to connect to the instance ID. This means no ssh keys are needed..
  ansible_host: instance_id
  ansible_connection: 'community.aws.aws_ssm'

command used:

❯ ansible-inventory --graph

Expected Results

I expect to get a graph output of instances grouped appropriately. This occurs as expected with the above inventory/aws_ec2.yml with amazon.aws collection version 5.5.0 and earlier.

Actual Results

ansible-inventory --graph
[WARNING]:  * Failed to parse /Users/<>/inventory/aws_ec2.yaml with ansible_collections.amazon.aws.plugins.inventory.aws_ec2 plugin: An error occurred
(ValidationException) when calling the GetInventory operation: 1 validation error detected: Value '[<instance ids list>]' at 'filters.1.member.values' failed to satisfy constraint: Member must have length less than or equal to 40
[WARNING]: Unable to parse /Users/<>/inventory/aws_ec2.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
@all:
  |--@ungrouped:

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot ansibullbot added bug This issue/PR relates to a bug inventory inventory plugin plugins plugin (any type) python3 labels Aug 29, 2023
@alinabuzachis alinabuzachis added needs_verified Some one might want to take a look at this and reproduce it to confirm and removed needs_triage labels Aug 31, 2023
@tomphill16
Copy link

The exact same thing is happening to me:

...at 'filters.1.member.values' failed to satisfy constraint: Member must have length less than or equal to 40

@liad5h
Copy link

liad5h commented Jan 15, 2024

same issue here

@vijayreddiar
Copy link

@abikouo The option use_ssm_inventory limits to use only if the number of instances in the syncing account is less than the allowed limit of instances for SSM send_command. Is it possible to sync the inventory in a batch with the option to apply the count of instances so that we can use it to keep it under the allowed limit of instances for SSM send_command?

softwarefactory-project-zuul bot pushed a commit that referenced this issue Jan 31, 2024
Bugfix aws_ec2 inventory use_ssm_inventory

SUMMARY
Fix bug where aws_ec2 inventory plugin was failing with use_ssm_inventory: true if there are more than 40 inventories.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ec2
ADDITIONAL INFORMATION
Fixes #1713

Reviewed-by: Bikouo Aubin
Reviewed-by: Mark Chappell
patchback bot pushed a commit that referenced this issue Jan 31, 2024
Bugfix aws_ec2 inventory use_ssm_inventory

SUMMARY
Fix bug where aws_ec2 inventory plugin was failing with use_ssm_inventory: true if there are more than 40 inventories.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ec2
ADDITIONAL INFORMATION
Fixes #1713

Reviewed-by: Bikouo Aubin
Reviewed-by: Mark Chappell
(cherry picked from commit 05c262a)
patchback bot pushed a commit that referenced this issue Jan 31, 2024
Bugfix aws_ec2 inventory use_ssm_inventory

SUMMARY
Fix bug where aws_ec2 inventory plugin was failing with use_ssm_inventory: true if there are more than 40 inventories.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ec2
ADDITIONAL INFORMATION
Fixes #1713

Reviewed-by: Bikouo Aubin
Reviewed-by: Mark Chappell
(cherry picked from commit 05c262a)
softwarefactory-project-zuul bot pushed a commit that referenced this issue Feb 5, 2024
[PR #1957/05c262a4 backport][stable-7] Bugfix aws_ec2 inventory use_ssm_inventory

This is a backport of PR #1957 as merged into main (05c262a).
SUMMARY
Fix bug where aws_ec2 inventory plugin was failing with use_ssm_inventory: true if there are more than 40 inventories.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ec2
ADDITIONAL INFORMATION
Fixes #1713

Reviewed-by: Mark Chappell
Reviewed-by: Alina Buzachis
softwarefactory-project-zuul bot pushed a commit that referenced this issue Feb 5, 2024
[PR #1957/05c262a4 backport][stable-6] Bugfix aws_ec2 inventory use_ssm_inventory

This is a backport of PR #1957 as merged into main (05c262a).
SUMMARY
Fix bug where aws_ec2 inventory plugin was failing with use_ssm_inventory: true if there are more than 40 inventories.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
aws_ec2
ADDITIONAL INFORMATION
Fixes #1713

Reviewed-by: Alina Buzachis
@vijayreddiar
Copy link

I see a fix is merged through #1957
Now, we don't see failures in inventory sync when the count of EC2 instances in an account is more than the allowed limit of instances (default value is 40) for SSM send_command, but no host variables are fetched through SSM now. The scenario is same even if the count of instances in the account is lesser than 40 - which means the parameter use_ssm_inventory is not at all effective now.

@gravesm
Copy link
Member

gravesm commented Feb 15, 2024

@vijayreddiar Please open a new issue for this.

@vijayreddiar
Copy link

@vijayreddiar Please open a new issue for this.

@gravesm I have raised a new issue. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug inventory inventory plugin needs_verified Some one might want to take a look at this and reproduce it to confirm plugins plugin (any type) python3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants