AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Search for AWS EC2 AMI ID by Region - Ansible module ec2_ami_info — Video Tutorial

How to automate the search of an AWS EC2 machine AMI ID running the operating system RHEL-8.3.0 in the region "us-east-1" using Ansible Playbook and ec2_ami_info module.

Watch Video

Watch "Search for AWS EC2 AMI ID by Region - Ansible module ec2_ami_info" on YouTube

What You'll Learn

Full Tutorial Content

How to Search for EC2 AMI ID by AWS Region with Ansible? I'm going to show you a live Playbook and some simple Ansible code. I'm Luca Berton and welcome to today's episode of Ansible Pilot. Ansible Search for EC2 AMI ID by AWS Region - `amazon.aws.ec2_ami_info` - Gather information about ec2 AMIs Let's talk about the Ansible module `ec2_ami_info`. The full name is `amazon.aws.ec2_ami_info`, which means that is part of the collection of modules to interact with AWS. The module's purpose is to gather information about ec2 AMIs. Parameters - filters _dictionary_ - filter terms Example: ```yaml name: "RHEL-8.3.0_HVM-*-x86_64-*Hourly*" region: "us-east-1" ``` The following parameters are useful in order to Search for EC2 AMI ID by AWS Region using the module `ec2_ami_info`. The only parameter needed is the `filters` and specify the filters keys and values. For example, let's search for Red Hat Enterprise Linux machines version 8.3.0 running on HVM infrastructure, architecture x86_64 Hourly paid. Links - [`amazon.aws.ec2_ami_info`](https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_ami_info_module.html) Playbook How to Search for EC2 AMI ID by AWS Region with Ansible. I'm going to show you how to Gather Information on a specific "`RHEL-8.3.0_HVM`" AWS EC2 Hourly Machine for the region "us-east-1" and select the EC2 AMI ID using Ansible Playbook. code ```yaml --- - name: AMI search hosts: localhost become: false gather_facts: false vars: aws_region: "us-east-1" aws_name: "RHEL-8.3.0_HVM-*-x86_64-*Hourly*" tasks: - name: search for AMI amazon.aws.ec2_ami_info: filters: name: "{{ aws_name }}" region: "{{ aws_region }}" register: ami_found - name: print AMI ansible.builtin.debug: var: ami_found ``` execution ```bash $ ansible-playbook ami_search.yml [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' PLAY [AMI search] ********************************************************************************* TASK [search for existing AMI] ******************************************************************** ok: [localhost] TASK [debug] ************************************************************************************** ok: [localhost] => { "ami_found": { "changed": false, "failed": false, "images": [ { "architecture": "x86_64", "block_device_mappings": [ { "device_name": "/dev/sda1", "ebs": { "delete_on_termination": true, "encrypted": false, "snapshot_id": "snap-03f2e24f30f580353", "volume_size": 10, "volume_type": "gp2" } } ],

About This Tutorial

Read the full written article: Search for AWS EC2 AMI ID by Region - Ansible module ec2_ami_info

Topics Covered

Related Video Tutorials