The `aws_ec2` inventory parses without errors but returns zero hosts
IntermediateTroubleshootingCloud, AWX, Windows and Molecule
Answer
Likely causes →
- The wrong
regions. - A tag filter with the wrong case (
tag:envagainsttag:Env). - The wrong AWS account or profile.
- Instances that are stopped while the filter asks for
running. - A stale inventory cache (
cache: true).
Diagnose →
aws sts get-caller-identity
aws ec2 describe-instances --region ap-south-1 --filters "Name=tag:Env,Values=prod" --query 'Reservations[].Instances[].InstanceId'
ansible-inventory -i prod.aws_ec2.yml --list -vvv | head -50
Fix → Align the filters with what the AWS CLI returns, set profile: or the environment credentials for the right account, and refresh with --flush-cache if caching is on.
Prevent → Standardise tag keys (for example Env, Role) enforced by Terraform or AWS Config, and alert when a key group comes back empty.
More on Cloud, AWX, Windows and Molecule
`Failed to import the required Python library (botocore and boto3) on web01's Python /usr/bin/python3.`Beginner`[WARNING]: * Failed to parse inventory/aws.yml with auto plugin: inventory source 'inventory/aws.yml' could not be verified by inventory plugin 'amazon.aws.aws_ec2'`Intermediate`Failed to describe instances: An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation` or `(ExpiredToken)`IntermediateDynamic inventory finds the instances, but every host is `UNREACHABLE`IntermediateUsing the SSM connection plugin fails with `SessionManagerPlugin is not found` or hangs on file transferAdvanced`winrm or requests is not installed: No module named 'winrm'`Beginner