Failed installation of Ansible in Amazon Linux 2022 Preview (AWS EC2) - Ansible install
By Luca Berton · Published 2024-01-01 · Category: installation
Failed installation of Ansible in Amazon Linux 2022 Preview (AWS EC2) using the internal and the EPEL (Extra Packages for Enterprise Linux) repositories.

How to install Ansible in Amazon Linux version 2022 Preview?
Today I'm trying to install Ansible in the newest Amazon Linux 2022 Preview. Spoiler alert: it didn't go well! I'm Luca Berton and welcome to today's episode of Ansible Pilot.See also: How to install Ansible in Amazon Linux 2 (AWS EC2) - Ansible install
Links
https://aws.amazon.com/it/linux/amazon-linux-2022/ https://aws.amazon.com/it/linux/amazon-linux-2022/faqs/ https://github.com/amazonlinux## Playbook
Let's jump in a quick live Playbook of how I tried to install the latest of Ansible in Amazon Linux 2022 Preview.
code
• Install-Ansible-Amazon Linux2022.sh#!/bin/bash
$ sudo yum update -y
$ sudo yum install ansible
$ ansible --version
execution
$ ssh -i key.pem ec2-user@34.245.160.35
__| __|_ )
_| ( / Amazon Linux 2022 AMI
___|\___|___| Preview
http://aws.amazon.com/linux/amazon-linux-2022
[ec2-user@ip-172-31-33-113 ~]$ cat /etc/image-id
image_name="al2022-ami"
image_version="2022"
image_arch="x86_64"
image_file="al2022-ami-2022.0.20211118.0-kernel-5.10-x86_64.xfs.gpt"
image_stamp="6548-3b38"
image_date="20211119011708"
recipe_name="al2022 ami"
recipe_id="a9b1edc7-a202-b09e-9e6e-3ad0-b75b-4a14-2961cce6"
[ec2-user@ip-172-31-33-113 ~]$ cat /etc/system-release
Amazon Linux release 2022 (Amazon Linux)
[ec2-user@ip-172-31-33-113 ~]$ cat /etc/os-release
NAME="Amazon Linux"
VERSION="2022"
ID="amzn"
ID_LIKE="fedora"
VERSION_ID="2022"
PLATFORM_ID="platform:al2022"
PRETTY_NAME="Amazon Linux 2022"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2022"
HOME_URL="https://amazonlinux.com/"
[ec2-user@ip-172-31-33-113 ~]$ sudo su
[root@ip-172-31-33-113 ec2-user]# yum install ansible
Last metadata expiration check: 0:07:05 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
No match for argument: ansible
Error: Unable to find a match: ansible
[root@ip-172-31-33-113 ec2-user]# yum install epel
Last metadata expiration check: 0:07:21 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
No match for argument: epel
Error: Unable to find a match: epel
[root@ip-172-31-33-113 ec2-user]# yum install epel-release
Last metadata expiration check: 0:07:27 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
No match for argument: epel-release
Error: Unable to find a match: epel-release
[root@ip-172-31-33-113 ec2-user]# yum repolist
repo id repo name
amazonlinux Amazon Linux 2022 repository
[root@ip-172-31-33-113 ec2-user]# yum search ansible
Last metadata expiration check: 0:08:35 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
No matches found.
[root@ip-172-31-33-113 ec2-user]# dnf update
Last metadata expiration check: 0:10:19 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
Dependencies resolved.
Nothing to do.
Complete!
[root@ip-172-31-33-113 ec2-user]# dnf repoinfo
Last metadata expiration check: 0:12:11 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
Repo-id : amazonlinux
Repo-name : Amazon Linux 2022 repository
Repo-revision : 1637274479
Repo-updated : Thu 18 Nov 2021 10:27:59 PM UTC
Repo-pkgs : 17,541
Repo-available-pkgs: 17,541
Repo-size : 18 G
Repo-mirrors : https://al2022-repos-eu-west-1-9761ab97.s3.dualstack.eu-west-1.amazonaws.com/core/mirrors/2022.0.20211118/x86_64/mirror.list
Repo-baseurl : https://al2022-repos-eu-west-1-9761ab97.s3.dualstack.eu-west-1.amazonaws.com/core/guids/0e6a211c72356e21402b561f1623752c9bfcd8a88b18993d5477d5f94327f88a/x86_64/
: (0 more)
Repo-expire : 172,800 second(s) (last: Sun 05 Dec 2021 12:51:14 PM UTC)
Repo-filename : /etc/yum.repos.d/amazonlinux.repo
Total packages: 17,541
[root@ip-172-31-33-113 ec2-user]# dnf install epel-next-release
Last metadata expiration check: 0:13:17 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
No match for argument: epel-next-release
Error: Unable to find a match: epel-next-release
[root@ip-172-31-33-113 ec2-user]# dnf install epel-release
Last metadata expiration check: 0:14:19 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
No match for argument: epel-release
Error: Unable to find a match: epel-release
[root@ip-172-31-33-113 ec2-user]# yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Last metadata expiration check: 0:14:59 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
epel-release-latest-8.noarch.rpm 53 kB/s | 23 kB 00:00
Error:
Problem: conflicting requests
- nothing provides redhat-release >= 8 needed by epel-release-8-13.el8.noarch
(try to add '--skip-broken' to skip uninstallable packages)
[root@ip-172-31-33-113 ec2-user]# dnf install redhat-release
Last metadata expiration check: 0:15:40 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
No match for argument: redhat-release
Error: Unable to find a match: redhat-release
[root@ip-172-31-33-113 ec2-user]# yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Last metadata expiration check: 0:15:45 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
epel-release-latest-7.noarch.rpm 41 kB/s | 15 kB 00:00
Error:
Problem: conflicting requests
- nothing provides redhat-release >= 7 needed by epel-release-7-14.noarch
(try to add '--skip-broken' to skip uninstallable packages)
[root@ip-172-31-33-113 ec2-user]# dnf install redhat-release
Last metadata expiration check: 0:15:49 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
No match for argument: redhat-release
Error: Unable to find a match: redhat-release
[root@ip-172-31-33-113 ec2-user]# cat /etc/image-id
image_name="al2022-ami"
image_version="2022"
image_arch="x86_64"
image_file="al2022-ami-2022.0.20211118.0-kernel-5.10-x86_64.xfs.gpt"
image_stamp="6548-3b38"
image_date="20211119011708"
recipe_name="al2022 ami"
recipe_id="a9b1edc7-a202-b09e-9e6e-3ad0-b75b-4a14-2961cce6"
[root@ip-172-31-33-113 ec2-user]# dnf install ansible
Last metadata expiration check: 0:18:12 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
No match for argument: ansible
Error: Unable to find a match: ansible
[root@ip-172-31-33-113 ec2-user]# dnf repoinfo
Last metadata expiration check: 0:18:37 ago on Sun 05 Dec 2021 12:51:14 PM UTC.
Repo-id : amazonlinux
Repo-name : Amazon Linux 2022 repository
Repo-revision : 1637274479
Repo-updated : Thu 18 Nov 2021 10:27:59 PM UTC
Repo-pkgs : 17,541
Repo-available-pkgs: 17,541
Repo-size : 18 G
Repo-mirrors : https://al2022-repos-eu-west-1-9761ab97.s3.dualstack.eu-west-1.amazonaws.com/core/mirrors/2022.0.20211118/x86_64/mirror.list
Repo-baseurl : https://al2022-repos-eu-west-1-9761ab97.s3.dualstack.eu-west-1.amazonaws.com/core/guids/0e6a211c72356e21402b561f1623752c9bfcd8a88b18993d5477d5f94327f88a/x86_64/
: (0 more)
Repo-expire : 172,800 second(s) (last: Sun 05 Dec 2021 12:51:14 PM UTC)
Repo-filename : /etc/yum.repos.d/amazonlinux.repo
Total packages: 17,541
[root@ip-172-31-33-113 ec2-user]#
Conclusion
Now you know how I tried to install Ansible in Amazon Linux 2022 and open a Package Request to the Amazon developer team.
See also: Master Ansible Automation for AWS: Complete Guide and Tutorials
Related Articles
• automating AWS with Ansible • role variables and defaults in AnsibleSee also
• How to install Ansible in Fedora 41See also: Ansible troubleshooting - AWS Failed to import the required Python library (botocore or boto3)
The Solution: Use pip to Install Ansible
Amazon Linux 2022 (now Amazon Linux 2023) doesn't include Ansible in its default repositories and doesn't support EPEL. The recommended approach is to use pip:
# Install Python 3 and pip
sudo dnf install -y python3 python3-pip
# Install Ansible via pip
python3 -m pip install --user ansible
# Verify installation
ansible --version
For Amazon Linux 2023
Amazon Linux 2023 (the GA successor to AL2022) includes ansible-core in its repos:
sudo dnf install -y ansible-core
Or for the full Ansible package with community collections:
sudo dnf install -y python3-pip
python3 -m pip install --user ansible
Why EPEL Doesn't Work on Amazon Linux 2022/2023
Amazon Linux 2022/2023 is based on Fedora (not RHEL), so EPEL packages built for RHEL 7, 8, or 9 have dependency conflicts. The redhat-release package isn't available, causing EPEL installation to fail.
Automate with Ansible
Use this playbook to install Ansible on Amazon Linux 2023 nodes:
---
- name: Install Ansible on Amazon Linux 2023
hosts: amazon_linux
become: true
tasks:
- name: Install ansible-core from repos
ansible.builtin.dnf:
name: ansible-core
state: present
- name: Install pip for additional collections
ansible.builtin.dnf:
name: python3-pip
state: present
- name: Install community collections
ansible.builtin.command:
cmd: ansible-galaxy collection install community.general
changed_when: true
FAQ
Can I install Ansible on Amazon Linux 2022 Preview?
Not directly from repositories. Amazon Linux 2022 Preview didn't include Ansible packages. Use pip install ansible instead.
What's the difference between Amazon Linux 2022 and 2023?
Amazon Linux 2022 was the preview name. The GA release was renamed to Amazon Linux 2023 (AL2023). AL2023 includes ansible-core in its default repos.
Should I use pip or dnf to install Ansible?
Use dnf install ansible-core for the base package on AL2023. Use pip install ansible if you need the full package with all community collections.
Does Amazon Linux 2023 support ansible-core or full ansible?
ansible-core is available via dnf. For the full ansible package (with bundled collections), use pip.
Category: installation
Watch the video: Failed installation of Ansible in Amazon Linux 2022 Preview (AWS EC2) - Ansible install — Video Tutorial