Introduction

When running a playbook that uses AWS modules, you may see:

ERROR! couldn't resolve module/action 'amazon.aws.ec2_ami_info'.
This often indicates a misspelling, missing collection, or incorrect module path.

This means the amazon.aws collection isn't installed. Here's how to fix it — and set up AWS authentication properly.

Quick Fix

ansible-galaxy collection install amazon.aws

Verify:

ansible-galaxy collection list | grep amazon.aws
# amazon.aws  7.2.0

Understanding the Error

The full error typically includes:

[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available
ERROR! couldn't resolve module/action 'amazon.aws.ec2_ami_info'

Three separate issues:

ErrorCauseFix
No inventory parsedMissing -i inventory flagAdd inventory file or use -i localhost,
Hosts list is emptyPlaybook targets undefined groupSet hosts: localhost for local AWS API calls
Couldn't resolve moduleCollection not installedansible-galaxy collection install amazon.aws

Install AWS Collections

Single Collection

ansible-galaxy collection install amazon.aws

With Version Pinning

ansible-galaxy collection install amazon.aws:==7.2.0
# requirements.yml
collections:
  - name: amazon.aws
    version: ">=7.0.0,<8.0.0"
  - name: community.aws
    version: ">=7.0.0,<8.0.0"
ansible-galaxy collection install -r requirements.yml

Install Python Dependencies

The AWS collections require boto3 and botocore:

pip install boto3 botocore

Verify:

python3 -c "import boto3; print(boto3.__version__)"

Configure AWS Authentication

Method 1: Environment Variables

export AWS_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE"
export AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
export AWS_DEFAULT_REGION="us-east-1"

Method 2: AWS CLI Profile

aws configure
# Enter access key, secret key, region, output format

Method 3: In Playbook (Use Vault!)

- name: Find AMIs
  amazon.aws.ec2_ami_info:
    aws_access_key: "{{ vault_aws_access_key }}"
    aws_secret_key: "{{ vault_aws_secret_key }}"
    region: us-east-1
    filters:
      name: "amzn2-ami-hvm-*-x86_64-gp2"
      state: available

Method 4: IAM Instance Profile

If running on EC2, attach an IAM role — no keys needed:

- name: Find AMIs (using instance profile)
  amazon.aws.ec2_ami_info:
    region: us-east-1
    filters:
      name: "amzn2-ami-hvm-*-x86_64-gp2"

Working Playbook Example

---
- name: Find latest Amazon Linux 2 AMI
  hosts: localhost
  connection: local
  gather_facts: false

  tasks:
    - name: Get AMI info
      amazon.aws.ec2_ami_info:
        region: us-east-1
        filters:
          name: "amzn2-ami-hvm-*-x86_64-gp2"
          state: available
          owner-alias: amazon
        owners:
          - amazon
      register: ami_result

    - name: Show latest AMI
      ansible.builtin.debug:
        msg: |
          AMI ID: {{ ami_result.images | sort(attribute='creation_date') | last | json_query('image_id') }}
          Name: {{ ami_result.images | sort(attribute='creation_date') | last | json_query('name') }}
          Created: {{ ami_result.images | sort(attribute='creation_date') | last | json_query('creation_date') }}

Common AWS Collection Modules

ModulePurpose
amazon.aws.ec2_ami_infoFind AMI details
amazon.aws.ec2_instanceManage EC2 instances
amazon.aws.ec2_vpc_netManage VPCs
amazon.aws.s3_bucketManage S3 buckets
amazon.aws.ec2_security_groupManage security groups
amazon.aws.iam_roleManage IAM roles
community.aws.ecs_taskdefinitionECS task definitions
community.aws.rds_instanceRDS databases

Troubleshooting

Collection Installed But Module Still Not Found

Check the collection path:

ansible-config dump | grep COLLECTIONS_PATH
# COLLECTIONS_PATHS = ['/home/user/.ansible/collections', '/usr/share/ansible/collections']

# List what's installed
ls ~/.ansible/collections/ansible_collections/amazon/aws/

Version Mismatch

Some modules were moved between collections or renamed:

# Old name (Ansible 2.9)
ec2_ami_info:

# New name (collections era)
amazon.aws.ec2_ami_info:

Virtual Environment Issues

If using a Python virtual environment, ensure the collection is installed in the right context:

# Activate venv first
source ~/.venvs/ansible/bin/activate
ansible-galaxy collection install amazon.aws
pip install boto3 botocore

Permissions Error During Install

# Install to user directory (default)
ansible-galaxy collection install amazon.aws

# Or specify a custom path
ansible-galaxy collection install amazon.aws -p ./collections
# Then set in ansible.cfg:
# [defaults]
# collections_path = ./collections

Conclusion

Install the collection with ansible-galaxy collection install amazon.aws, install Python dependencies with pip install boto3 botocore, set hosts: localhost and connection: local for API calls, and configure AWS credentials via environment variables, AWS CLI profile, or IAM instance role. Use requirements.yml with version pinning for reproducible environments.