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:
- No inventory parsed: Indicates that Ansible did not detect a valid inventory file, which is essential for defining the hosts on which the playbook operates.
- Provided hosts list is empty: Suggests that the playbook does not specify a target host or group of hosts for the tasks.
- Couldn’t resolve module/action ‘amazon.aws.ec2_ami_info’: The main issue, pointing to Ansible’s inability to find the specified module.
Troubleshooting Steps
To resolve these issues and ensure smooth playbook execution, the following steps can be taken:
Ensure Collection Installation: The ‘amazon.aws.ec2_ami_info’ module is part of the
amazon.aws
collection. Ensure this collection is installed by runningansible-galaxy collection install amazon.aws
. If the collection is not installed, Ansible cannot find the module.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.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.
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.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.
Example Corrected
- Playbook Snippet
- 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"
- Collection installation
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 Udemy 300+ Lessons Video Course.
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate