Ansible Pilot

Ansible troubleshooting - Resolving The Case of the Missing amazon.aws.ec2_ami_info Module

A Comprehensive Guide to Overcoming Common Ansible Playbook Challenges

February 3, 2024
Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons

Introduction

In the realm of IT automation, Ansible playbooks are a cornerstone, empowering administrators and developers to define and execute a series of tasks across a multitude of servers in an orderly and predictable manner. However, even the most seasoned professionals can encounter hurdles, such as the intriguing issue of a playbook failing to execute due to a missing module. A classic example of this scenario is encountered with the error message regarding the ‘amazon.aws.ec2_ami_info’ module.

Understanding the Problem

The error message in question is encountered when running an Ansible playbook aimed at gathering information about Amazon Machine Images (AMIs) using the amazon.aws.ec2_ami_info module. The message highlights a failure to parse inventory, a lack of available hosts, and crucially, the inability to resolve the ‘amazon.aws.ec2_ami_info’ module. This error is particularly perplexing as it suggests a misspelling, a missing collection, or an incorrect module path, which halts the playbook execution.

Analyzing the Error

The error message provides several clues:

Troubleshooting Steps

To resolve these issues and ensure smooth playbook execution, the following steps can be taken:

  1. Ensure Collection Installation: The ‘amazon.aws.ec2_ami_info’ module is part of the amazon.aws collection. Ensure this collection is installed by running ansible-galaxy collection install amazon.aws. If the collection is not installed, Ansible cannot find the module.

  2. Verify Inventory File: Ensure that an inventory file is present and correctly formatted. If you’re running the playbook against AWS EC2 instances, your inventory might be dynamic. Verify the configuration or explicitly define the inventory in the playbook command using the -i option.

  3. Specify Hosts in Playbook: Make sure the playbook specifies a valid hosts parameter. If you’re targeting EC2 instances, you might use a dynamic inventory or a group defined in your static inventory file.

  4. Check Module Name and Path: Verify that the module name ’ec2_ami_info’ is correct and that no typographical errors are present. Since this is part of the amazon.aws collection, the correct usage involves specifying the full collection namespace, as shown in the error message.

  5. Update Ansible and Collections: Ensure that your Ansible and amazon.aws collection are up to date. Sometimes, modules are added, deprecated, or moved in newer versions.

The Best Resources For Ansible

Certifications

Video Course

Printed Book

eBooks

Example Corrected

- hosts: localhost
  gather_facts: no
  collections:
    - amazon.aws
  tasks:
    - name: Find AMI
      ec2_ami_info:
        filters:
          name: "amzn2-ami-hvm-*-x86_64-gp2"
          state: "available"
Starting galaxy collection install process
[WARNING]: Error parsing collection metadata requires_ansible value from collection
prometheus.prometheus: Invalid specifier: '2.9'
Process install dependency map
Starting collection install process
Downloading https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/artifacts/amazon-aws-7.2.0.tar.gz to /Users/lberton/.ansible/tmp/ansible-local-94460hj40664m/tmp2k157ter/amazon-aws-7.2.0-g42hnfpd
Installing 'amazon.aws:7.2.0' to '/Users/lberton/.ansible/collections/ansible_collections/amazon/aws'
amazon.aws:7.2.0 was installed successfully

Conclusion

Encountering errors with Ansible playbooks can be a frustrating experience, but it’s also an opportunity to deepen one’s understanding of Ansible’s workings and best practices. By methodically analyzing and addressing each component of the error message, administrators and developers can overcome obstacles and harness the full power of Ansible for automation. Remember, the key to resolving such issues lies in ensuring that collections are installed, inventory is correctly parsed, and modules are correctly referenced within the playbook.

Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.

Academy

Learn the Ansible automation technology with some real-life examples in my

My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Want to keep this project going? Please donate

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons
Follow me

Subscribe not to miss any new releases