AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 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 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", 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.

How to install Ansible in Amazon Linux 2 (AWS EC2) - Ansible install

By Luca Berton · Published 2024-01-01 · Category: installation

How to install Ansible in Amazon Linux 2 using the Amazon Extras Library \\"amazon-linux-extras\\" and the EPEL (Extra Packages for Enterprise Linux).

How to install Ansible in Amazon Linux 2 (AWS EC2) - Ansible install

How to install Ansible in Amazon Linux version 2? Today we're going to talk about the easier way to install and maintain Ansible inside Amazon Linux 2 using the Amazon Extras Library and EPEL repositories. I'm Luca Berton and welcome to today's episode of Ansible Pilot.

How to install Ansible in Amazon Linux 2

• "ansible2" topic in Extras Library repository • "ansible" in Extra Packages for Enterprise Linux (EPEL) additional packages for Enterprise Linux: Red Hat Enterprise Linux (RHEL), Rocky Linux and Scientific Linux (SL), Oracle Linux (OL), and Amazon Linux

Today we're talking about How to install Ansible in Amazon Linux 2. The good news is that Ansible is included in the Extras Library included in Amazon Linux 2 repository using the "amazon-linux-extras" command. Another option is to install and maintain Ansible inside Amazon Linux 2 is using the Extra Packages for Enterprise Linux (EPEL) additional repository. This repository is maintained by the Fedora Special Interest Group and manages a high-quality set of additional packages for Enterprise Linux: Red Hat Enterprise Linux (RHEL), Rocky Linux and Scientific Linux (SL), Oracle Linux (OL), and Amazon Linux.

See also: Failed installation of Ansible in Amazon Linux 2022 Preview (AWS EC2) - Ansible install

Links

Amazon Linux 2How do I enable the EPEL repository for my Amazon EC2 instance running CentOS, RHEL, or Amazon Linux?Extras library (Amazon Linux 2)Extra Packages for Enterprise Linux (EPEL)

Playbook

Install Ansible in Amazon Linux (EC2) 2 using the Amazon Extras Library and EPEL repositories.

Here are the steps on how to install Ansible in Amazon Linux 2 (AWS EC2): Update the package list:

$ sudo yum update -y
Install the Ansible package:
$ sudo amazon-linux-extras install ansible2 -y
Check the Ansible version:
$ ansible --version
Verify that Ansible is installed correctly by running a simple playbook:
$ ansible localhost -m ping

This playbook will print the following output:

localhost | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

If you see this output, then Ansible is installed and configured correctly.

Amazon Extras Library code

• Install-Ansible-Amazon Linux2-Amazon Extras Library.sh
#!/bin/bash
$ sudo yum update -y
$ sudo amazon-linux-extras install ansible2 -y
$ ansible --version

Amazon Extras Library execution

$ ssh -i key.pem ec2-user@34.241.249.206

__| __|_ ) _| ( / Amazon Linux 2 AMI ___|\___|___|

https://aws.amazon.com/amazon-linux-2/ -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory [ec2-user@ip-172-31-36-49 ~]$ sudo su [root@ip-172-31-36-49 ec2-user]# cat /etc/image-id image_name="amzn2-ami-kernel-5.10-hvm" image_version="2" image_arch="x86_64" image_file="amzn2-ami-kernel-5.10-hvm-2.0.20211201.0-x86_64.xfs.gpt" image_stamp="7143-c998" image_date="20211201182203" recipe_name="amzn2 ami" recipe_id="d46c60d3-613d-8f76-a3cd-4476-405e-a3e2-088c7229" [root@ip-172-31-36-49 ec2-user]# cat /etc/os-release NAME="Amazon Linux" VERSION="2" ID="amzn" ID_LIKE="centos rhel fedora" VERSION_ID="2" PRETTY_NAME="Amazon Linux 2" ANSI_COLOR="0;33" CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2" HOME_URL="https://amazonlinux.com/" [root@ip-172-31-36-49 ec2-user]# cat /etc/os-release NAME="Amazon Linux" VERSION="2" ID="amzn" ID_LIKE="centos rhel fedora" VERSION_ID="2" PRETTY_NAME="Amazon Linux 2" ANSI_COLOR="0;33" CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2" HOME_URL="https://amazonlinux.com/" [root@ip-172-31-36-49 ec2-user]# yum update Failed to set locale, defaulting to C Loaded plugins: extras_suggestions, langpacks, priorities, update-motd amzn2-core | 3.7 kB 00:00:00 amzn2extra-docker | 3.0 kB 00:00:00 amzn2extra-kernel-5.10 | 3.0 kB 00:00:00 No packages marked for update [root@ip-172-31-36-49 ec2-user]# amazon-linux-extras install ansible2 Installing ansible Failed to set locale, defaulting to C Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Cleaning repos: amzn2-core amzn2extra-ansible2 amzn2extra-docker amzn2extra-kernel-5.10 17 metadata files removed 6 sqlite files removed 0 metadata files removed Failed to set locale, defaulting to C Loaded plugins: extras_suggestions, langpacks, priorities, update-motd amzn2-core | 3.7 kB 00:00:00 amzn2extra-ansible2 | 3.0 kB 00:00:00 amzn2extra-docker | 3.0 kB 00:00:00 amzn2extra-kernel-5.10 | 3.0 kB 00:00:00 (1/9): amzn2-core/2/x86_64/group_gz | 2.5 kB 00:00:00 (2/9): amzn2-core/2/x86_64/updateinfo | 424 kB 00:00:00 (3/9): amzn2extra-docker/2/x86_64/primary_db | 86 kB 00:00:00 (4/9): amzn2extra-kernel-5.10/2/x86_64/updateinfo | 76 B 00:00:00 (5/9): amzn2extra-kernel-5.10/2/x86_64/primary_db | 5.3 MB 00:00:00 (6/9): amzn2extra-ansible2/2/x86_64/primary_db | 39 kB 00:00:00 (7/9): amzn2extra-docker/2/x86_64/updateinfo | 4.7 kB 00:00:00 (8/9): amzn2extra-ansible2/2/x86_64/updateinfo | 76 B 00:00:00 (9/9): amzn2-core/2/x86_64/primary_db | 58 MB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package ansible.noarch 0:2.9.23-1.amzn2 will be installed --> Processing Dependency: sshpass for package: ansible-2.9.23-1.amzn2.noarch --> Processing Dependency: python-paramiko for package: ansible-2.9.23-1.amzn2.noarch --> Processing Dependency: python-keyczar for package: ansible-2.9.23-1.amzn2.noarch --> Processing Dependency: python-httplib2 for package: ansible-2.9.23-1.amzn2.noarch --> Processing Dependency: python-crypto for package: ansible-2.9.23-1.amzn2.noarch --> Running transaction check ---> Package python-keyczar.noarch 0:0.71c-2.amzn2 will be installed ---> Package python2-crypto.x86_64 0:2.6.1-13.amzn2.0.3 will be installed --> Processing Dependency: libtomcrypt.so.1()(64bit) for package: python2-crypto-2.6.1-13.amzn2.0.3.x86_64 ---> Package python2-httplib2.noarch 0:0.18.1-3.amzn2 will be installed ---> Package python2-paramiko.noarch 0:1.16.1-3.amzn2.0.2 will be installed --> Processing Dependency: python2-ecdsa for package: python2-paramiko-1.16.1-3.amzn2.0.2.noarch ---> Package sshpass.x86_64 0:1.06-1.amzn2.0.1 will be installed --> Running transaction check ---> Package libtomcrypt.x86_64 0:1.18.2-1.amzn2.0.1 will be installed --> Processing Dependency: libtommath >= 1.0 for package: libtomcrypt-1.18.2-1.amzn2.0.1.x86_64 --> Processing Dependency: libtommath.so.1()(64bit) for package: libtomcrypt-1.18.2-1.amzn2.0.1.x86_64 ---> Package python2-ecdsa.noarch 0:0.13.3-1.amzn2.0.1 will be installed --> Running transaction check ---> Package libtommath.x86_64 0:1.0.1-4.amzn2.0.1 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================== Package Arch Version Repository Size =================================================================================================== Installing: ansible noarch 2.9.23-1.amzn2 amzn2extra-ansible2 17 M Installing for dependencies: libtomcrypt x86_64 1.18.2-1.amzn2.0.1 amzn2extra-ansible2 409 k libtommath x86_64 1.0.1-4.amzn2.0.1 amzn2extra-ansible2 36 k python-keyczar noarch 0.71c-2.amzn2 amzn2extra-ansible2 218 k python2-crypto x86_64 2.6.1-13.amzn2.0.3 amzn2extra-ansible2 476 k python2-ecdsa noarch 0.13.3-1.amzn2.0.1 amzn2extra-ansible2 94 k python2-httplib2 noarch 0.18.1-3.amzn2 amzn2extra-ansible2 125 k python2-paramiko noarch 1.16.1-3.amzn2.0.2 amzn2extra-ansible2 259 k sshpass x86_64 1.06-1.amzn2.0.1 amzn2extra-ansible2 22 k Transaction Summary =================================================================================================== Install 1 Package (+8 Dependent packages) Total download size: 19 M Installed size: 110 M Is this ok [y/d/N]: y Downloading packages: (1/9): libtomcrypt-1.18.2-1.amzn2.0.1.x86_64.rpm | 409 kB 00:00:00 (2/9): libtommath-1.0.1-4.amzn2.0.1.x86_64.rpm | 36 kB 00:00:00 (3/9): python-keyczar-0.71c-2.amzn2.noarch.rpm | 218 kB 00:00:00 (4/9): python2-crypto-2.6.1-13.amzn2.0.3.x86_64.rpm | 476 kB 00:00:00 (5/9): ansible-2.9.23-1.amzn2.noarch.rpm | 17 MB 00:00:00 (6/9): python2-ecdsa-0.13.3-1.amzn2.0.1.noarch.rpm | 94 kB 00:00:00 (7/9): python2-httplib2-0.18.1-3.amzn2.noarch.rpm | 125 kB 00:00:00 (8/9): sshpass-1.06-1.amzn2.0.1.x86_64.rpm | 22 kB 00:00:00 (9/9): python2-paramiko-1.16.1-3.amzn2.0.2.noarch.rpm | 259 kB 00:00:00 --------------------------------------------------------------------------------------------------- Total 44 MB/s | 19 MB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : sshpass-1.06-1.amzn2.0.1.x86_64 1/9 Installing : python2-httplib2-0.18.1-3.amzn2.noarch 2/9 Installing : libtommath-1.0.1-4.amzn2.0.1.x86_64 3/9 Installing : libtomcrypt-1.18.2-1.amzn2.0.1.x86_64 4/9 Installing : python2-crypto-2.6.1-13.amzn2.0.3.x86_64 5/9 Installing : python-keyczar-0.71c-2.amzn2.noarch 6/9 Installing : python2-ecdsa-0.13.3-1.amzn2.0.1.noarch 7/9 Installing : python2-paramiko-1.16.1-3.amzn2.0.2.noarch 8/9 Installing : ansible-2.9.23-1.amzn2.noarch 9/9 Verifying : python2-ecdsa-0.13.3-1.amzn2.0.1.noarch 1/9 Verifying : libtommath-1.0.1-4.amzn2.0.1.x86_64 2/9 Verifying : python2-crypto-2.6.1-13.amzn2.0.3.x86_64 3/9 Verifying : ansible-2.9.23-1.amzn2.noarch 4/9 Verifying : python-keyczar-0.71c-2.amzn2.noarch 5/9 Verifying : libtomcrypt-1.18.2-1.amzn2.0.1.x86_64 6/9 Verifying : python2-paramiko-1.16.1-3.amzn2.0.2.noarch 7/9 Verifying : python2-httplib2-0.18.1-3.amzn2.noarch 8/9 Verifying : sshpass-1.06-1.amzn2.0.1.x86_64 9/9 Installed: ansible.noarch 0:2.9.23-1.amzn2 Dependency Installed: libtomcrypt.x86_64 0:1.18.2-1.amzn2.0.1 libtommath.x86_64 0:1.0.1-4.amzn2.0.1 python-keyczar.noarch 0:0.71c-2.amzn2 python2-crypto.x86_64 0:2.6.1-13.amzn2.0.3 python2-ecdsa.noarch 0:0.13.3-1.amzn2.0.1 python2-httplib2.noarch 0:0.18.1-3.amzn2 python2-paramiko.noarch 0:1.16.1-3.amzn2.0.2 sshpass.x86_64 0:1.06-1.amzn2.0.1 Complete! 0 ansible2=latest enabled \ [ =2.4.2 =2.4.6 =2.8 =stable ] 2 httpd_modules available [ =1.0 =stable ] 3 memcached1.5 available \ [ =1.5.1 =1.5.16 =1.5.17 ] 5 postgresql9.6 available \ [ =9.6.6 =9.6.8 =stable ] 6 postgresql10 available [ =10 =stable ] 9 R3.4 available [ =3.4.3 =stable ] 10 rust1 available \ [ =1.22.1 =1.26.0 =1.26.1 =1.27.2 =1.31.0 =1.38.0 =stable ] 11 vim available [ =8.0 =stable ] 15 php7.2 available \ [ =7.2.0 =7.2.4 =7.2.5 =7.2.8 =7.2.11 =7.2.13 =7.2.14 =7.2.16 =7.2.17 =7.2.19 =7.2.21 =7.2.22 =7.2.23 =7.2.24 =7.2.26 =stable ] 17 lamp-mariadb10.2-php7.2 available \ [ =10.2.10_7.2.0 =10.2.10_7.2.4 =10.2.10_7.2.5 =10.2.10_7.2.8 =10.2.10_7.2.11 =10.2.10_7.2.13 =10.2.10_7.2.14 =10.2.10_7.2.16 =10.2.10_7.2.17 =10.2.10_7.2.19 =10.2.10_7.2.22 =10.2.10_7.2.23 =10.2.10_7.2.24 =stable ] 18 libreoffice available \ [ =5.0.6.2_15 =5.3.6.1 =stable ] 19 gimp available [ =2.8.22 ] 20 docker=latest enabled \ [ =17.12.1 =18.03.1 =18.06.1 =18.09.9 =stable ] 21 mate-desktop1.x available \ [ =1.19.0 =1.20.0 =stable ] 22 GraphicsMagick1.3 available \ [ =1.3.29 =1.3.32 =1.3.34 =stable ] 23 tomcat8.5 available \ [ =8.5.31 =8.5.32 =8.5.38 =8.5.40 =8.5.42 =8.5.50 =stable ] 24 epel available [ =7.11 =stable ] 25 testing available [ =1.0 =stable ] 26 ecs available [ =stable ] 27 corretto8 available \ [ =1.8.0_192 =1.8.0_202 =1.8.0_212 =1.8.0_222 =1.8.0_232 =1.8.0_242 =stable ] 28 firecracker available [ =0.11 =stable ] 29 golang1.11 available \ [ =1.11.3 =1.11.11 =1.11.13 =stable ] 30 squid4 available [ =4 =stable ] 31 php7.3 available \ [ =7.3.2 =7.3.3 =7.3.4 =7.3.6 =7.3.8 =7.3.9 =7.3.10 =7.3.11 =7.3.13 =stable ] 32 lustre2.10 available \ [ =2.10.5 =2.10.8 =stable ] 33 java-openjdk11 available [ =11 =stable ] 34 lynis available [ =stable ] 35 kernel-ng available [ =stable ] 36 BCC available [ =0.x =stable ] 37 mono available [ =5.x =stable ] 38 nginx1 available [ =stable ] 39 ruby2.6 available [ =2.6 =stable ] 40 mock available [ =stable ] 41 postgresql11 available [ =11 =stable ] 42 php7.4 available [ =stable ] 43 livepatch available [ =stable ] 44 python3.8 available [ =stable ] 45 haproxy2 available [ =stable ] 46 collectd available [ =stable ] 47 aws-nitro-enclaves-cli available [ =stable ] 48 R4 available [ =stable ] _ kernel-5.4 available [ =stable ] 50 selinux-ng available [ =stable ] 51 php8.0 available [ =stable ] 52 tomcat9 available [ =stable ] 53 unbound1.13 available [ =stable ] 54 mariadb10.5 available [ =stable ] 55 kernel-5.10=latest enabled [ =stable ] 56 redis6 available [ =stable ] 57 ruby3.0 available [ =stable ] 58 postgresql12 available [ =stable ] 59 postgresql13 available [ =stable ] 60 mock2 available [ =stable ] 61 dnsmasq2.85 available [ =stable ] [root@ip-172-31-36-49 ec2-user]# ansible --version ansible 2.9.23 config file = /etc/ansible/ansible.cfg configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /bin/ansible python version = 2.7.18 (default, Jun 10 2021, 00:11:02) [GCC 7.3.1 20180712 (Red Hat 7.3.1-13)] [root@ip-172-31-36-49 ec2-user]# rpm -qa | grep ansible ansible-2.9.23-1.amzn2.noarch [root@ip-172-31-36-49 ec2-user]#

Amazon Extras Library after execution

# rpm -qa | grep ansible
ansible-2.9.23-1.amzn2.noarch

EPEL code

• Install-Ansible-Amazon Linux2-EPEL.sh
#!/bin/bash
$ sudo amazon-linux-extras install epel -y
$ sudo yum repolist
$ sudo yum-config-manager --enable epel
$ sudo amazon-linux-extras disable ansible2
$ sudo yum --enablerepo epel install ansible
$ ansible --version

EPEL execution

# yum remove ansible
Failed to set locale, defaulting to C
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
---> Package ansible.noarch 0:2.9.23-1.amzn2 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================================================
 Package           Arch             Version                   Repository                      Size
===================================================================================================
Removing:
 ansible           noarch           2.9.23-1.amzn2            @amzn2extra-ansible2           105 M
Transaction Summary
===================================================================================================
Remove  1 Package
Installed size: 105 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : ansible-2.9.23-1.amzn2.noarch                                                   1/1 
  Verifying  : ansible-2.9.23-1.amzn2.noarch                                                   1/1
Removed:
  ansible.noarch 0:2.9.23-1.amzn2
Complete!
[root@ip-172-31-36-49 ec2-user]# amazon-linux-extras install epel
Installing epel-release
Failed to set locale, defaulting to C
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-ansible2 amzn2extra-docker amzn2extra-epel
              : amzn2extra-kernel-5.10
22 metadata files removed
8 sqlite files removed
0 metadata files removed
Failed to set locale, defaulting to C
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                  | 3.7 kB  00:00:00     
amzn2extra-ansible2                                                         | 3.0 kB  00:00:00     
amzn2extra-docker                                                           | 3.0 kB  00:00:00     
amzn2extra-epel                                                             | 3.0 kB  00:00:00     
amzn2extra-kernel-5.10                                                      | 3.0 kB  00:00:00     
(1/11): amzn2-core/2/x86_64/group_gz                                        | 2.5 kB  00:00:00     
(2/11): amzn2-core/2/x86_64/updateinfo                                      | 424 kB  00:00:00     
(3/11): amzn2extra-docker/2/x86_64/primary_db                               |  86 kB  00:00:00     
(4/11): amzn2extra-epel/2/x86_64/updateinfo                                 |   76 B  00:00:00     
(5/11): amzn2extra-epel/2/x86_64/primary_db                                 | 1.8 kB  00:00:00     
(6/11): amzn2extra-kernel-5.10/2/x86_64/updateinfo                          |   76 B  00:00:00     
(7/11): amzn2extra-kernel-5.10/2/x86_64/primary_db                          | 5.3 MB  00:00:00     
(8/11): amzn2extra-ansible2/2/x86_64/updateinfo                             |   76 B  00:00:00     
(9/11): amzn2extra-docker/2/x86_64/updateinfo                               | 4.7 kB  00:00:00     
(10/11): amzn2extra-ansible2/2/x86_64/primary_db                            |  39 kB  00:00:00     
(11/11): amzn2-core/2/x86_64/primary_db                                     |  58 MB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================================================
 Package                  Arch               Version             Repository                   Size
===================================================================================================
Installing:
 epel-release             noarch             7-11                amzn2extra-epel              15 k
Transaction Summary
===================================================================================================
Install  1 Package
Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-11.noarch.rpm                                                |  15 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                                        1/1 
  Verifying  : epel-release-7-11.noarch                                                        1/1
Installed:
  epel-release.noarch 0:7-11
Complete!
  0  ansible2=latest          enabled      \
        [ =2.4.2  =2.4.6  =2.8  =stable ]
  2  httpd_modules            available    [ =1.0  =stable ]
  3  memcached1.5             available    \
        [ =1.5.1  =1.5.16  =1.5.17 ]
  5  postgresql9.6            available    \
        [ =9.6.6  =9.6.8  =stable ]
  6  postgresql10             available    [ =10  =stable ]
  9  R3.4                     available    [ =3.4.3  =stable ]
 10  rust1                    available    \
        [ =1.22.1  =1.26.0  =1.26.1  =1.27.2  =1.31.0  =1.38.0
          =stable ]
 11  vim                      available    [ =8.0  =stable ]
 15  php7.2                   available    \
        [ =7.2.0  =7.2.4  =7.2.5  =7.2.8  =7.2.11  =7.2.13  =7.2.14
          =7.2.16  =7.2.17  =7.2.19  =7.2.21  =7.2.22  =7.2.23
          =7.2.24  =7.2.26  =stable ]
 17  lamp-mariadb10.2-php7.2  available    \
        [ =10.2.10_7.2.0  =10.2.10_7.2.4  =10.2.10_7.2.5
          =10.2.10_7.2.8  =10.2.10_7.2.11  =10.2.10_7.2.13
          =10.2.10_7.2.14  =10.2.10_7.2.16  =10.2.10_7.2.17
          =10.2.10_7.2.19  =10.2.10_7.2.22  =10.2.10_7.2.23
          =10.2.10_7.2.24  =stable ]
 18  libreoffice              available    \
        [ =5.0.6.2_15  =5.3.6.1  =stable ]
 19  gimp                     available    [ =2.8.22 ]
 20  docker=latest            enabled      \
        [ =17.12.1  =18.03.1  =18.06.1  =18.09.9  =stable ]
 21  mate-desktop1.x          available    \
        [ =1.19.0  =1.20.0  =stable ]
 22  GraphicsMagick1.3        available    \
        [ =1.3.29  =1.3.32  =1.3.34  =stable ]
 23  tomcat8.5                available    \
        [ =8.5.31  =8.5.32  =8.5.38  =8.5.40  =8.5.42  =8.5.50
          =stable ]
 24  epel=latest              enabled      [ =7.11  =stable ]
 25  testing                  available    [ =1.0  =stable ]
 26  ecs                      available    [ =stable ]
 27  corretto8                available    \
        [ =1.8.0_192  =1.8.0_202  =1.8.0_212  =1.8.0_222  =1.8.0_232
          =1.8.0_242  =stable ]
 28  firecracker              available    [ =0.11  =stable ]
 29  golang1.11               available    \
        [ =1.11.3  =1.11.11  =1.11.13  =stable ]
 30  squid4                   available    [ =4  =stable ]
 31  php7.3                   available    \
        [ =7.3.2  =7.3.3  =7.3.4  =7.3.6  =7.3.8  =7.3.9  =7.3.10
          =7.3.11  =7.3.13  =stable ]
 32  lustre2.10               available    \
        [ =2.10.5  =2.10.8  =stable ]
 33  java-openjdk11           available    [ =11  =stable ]
 34  lynis                    available    [ =stable ]
 35  kernel-ng                available    [ =stable ]
 36  BCC                      available    [ =0.x  =stable ]
 37  mono                     available    [ =5.x  =stable ]
 38  nginx1                   available    [ =stable ]
 39  ruby2.6                  available    [ =2.6  =stable ]
 40  mock                     available    [ =stable ]
 41  postgresql11             available    [ =11  =stable ]
 42  php7.4                   available    [ =stable ]
 43  livepatch                available    [ =stable ]
 44  python3.8                available    [ =stable ]
 45  haproxy2                 available    [ =stable ]
 46  collectd                 available    [ =stable ]
 47  aws-nitro-enclaves-cli   available    [ =stable ]
 48  R4                       available    [ =stable ]
  _  kernel-5.4               available    [ =stable ]
 50  selinux-ng               available    [ =stable ]
 51  php8.0                   available    [ =stable ]
 52  tomcat9                  available    [ =stable ]
 53  unbound1.13              available    [ =stable ]
 54  mariadb10.5              available    [ =stable ]
 55  kernel-5.10=latest       enabled      [ =stable ]
 56  redis6                   available    [ =stable ]
 57  ruby3.0                  available    [ =stable ]
 58  postgresql12             available    [ =stable ]
 59  postgresql13             available    [ =stable ]
 60  mock2                    available    [ =stable ]
 61  dnsmasq2.85              available    [ =stable ]
[root@ip-172-31-36-49 ec2-user]# yum repolist
Failed to set locale, defaulting to C
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Existing lock /var/run/yum.pid: another copy is running as pid 4695.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory : 110 M RSS (402 MB VSZ)
    Started: Sun Dec  5 10:04:44 2021 - 00:09 ago
    State  : Running, pid: 4695
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory : 273 M RSS (565 MB VSZ)
    Started: Sun Dec  5 10:04:44 2021 - 00:11 ago
    State  : Running, pid: 4695
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory : 318 M RSS (610 MB VSZ)
    Started: Sun Dec  5 10:04:44 2021 - 00:13 ago
    State  : Running, pid: 4695
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory : 322 M RSS (614 MB VSZ)
    Started: Sun Dec  5 10:04:44 2021 - 00:15 ago
    State  : Running, pid: 4695
225 packages excluded due to repository priority protections
repo id                              repo name                                            status
amzn2-core/2/x86_64                  Amazon Linux 2 core repository                           26819
amzn2extra-ansible2/2/x86_64         Amazon Extras repo for ansible2                             63
amzn2extra-docker/2/x86_64           Amazon Extras repo for docker                               55
amzn2extra-epel/2/x86_64             Amazon Extras repo for epel                                  1
amzn2extra-kernel-5.10/2/x86_64      Amazon Extras repo for kernel-5.10                          86
epel/x86_64                          Extra Packages for Enterprise Linux 7 - x86_64       13464+225
repolist: 40488
[root@ip-172-31-36-49 ec2-user]# amazon-linux-extras disable ansible2
Beware that disabling topics is not supported after they are installed.
  0  ansible2                 available    \
        [ =2.4.2  =2.4.6  =2.8  =stable ]
  2  httpd_modules            available    [ =1.0  =stable ]
  3  memcached1.5             available    \
        [ =1.5.1  =1.5.16  =1.5.17 ]
  5  postgresql9.6            available    \
        [ =9.6.6  =9.6.8  =stable ]
  6  postgresql10             available    [ =10  =stable ]
  9  R3.4                     available    [ =3.4.3  =stable ]
 10  rust1                    available    \
        [ =1.22.1  =1.26.0  =1.26.1  =1.27.2  =1.31.0  =1.38.0
          =stable ]
 11  vim                      available    [ =8.0  =stable ]
 15  php7.2                   available    \
        [ =7.2.0  =7.2.4  =7.2.5  =7.2.8  =7.2.11  =7.2.13  =7.2.14
          =7.2.16  =7.2.17  =7.2.19  =7.2.21  =7.2.22  =7.2.23
          =7.2.24  =7.2.26  =stable ]
 17  lamp-mariadb10.2-php7.2  available    \
        [ =10.2.10_7.2.0  =10.2.10_7.2.4  =10.2.10_7.2.5
          =10.2.10_7.2.8  =10.2.10_7.2.11  =10.2.10_7.2.13
          =10.2.10_7.2.14  =10.2.10_7.2.16  =10.2.10_7.2.17
          =10.2.10_7.2.19  =10.2.10_7.2.22  =10.2.10_7.2.23
          =10.2.10_7.2.24  =stable ]
 18  libreoffice              available    \
        [ =5.0.6.2_15  =5.3.6.1  =stable ]
 19  gimp                     available    [ =2.8.22 ]
 20  docker=latest            enabled      \
        [ =17.12.1  =18.03.1  =18.06.1  =18.09.9  =stable ]
 21  mate-desktop1.x          available    \
        [ =1.19.0  =1.20.0  =stable ]
 22  GraphicsMagick1.3        available    \
        [ =1.3.29  =1.3.32  =1.3.34  =stable ]
 23  tomcat8.5                available    \
        [ =8.5.31  =8.5.32  =8.5.38  =8.5.40  =8.5.42  =8.5.50
          =stable ]
 24  epel=latest              enabled      [ =7.11  =stable ]
 25  testing                  available    [ =1.0  =stable ]
 26  ecs                      available    [ =stable ]
 27  corretto8                available    \
        [ =1.8.0_192  =1.8.0_202  =1.8.0_212  =1.8.0_222  =1.8.0_232
          =1.8.0_242  =stable ]
 28  firecracker              available    [ =0.11  =stable ]
 29  golang1.11               available    \
        [ =1.11.3  =1.11.11  =1.11.13  =stable ]
 30  squid4                   available    [ =4  =stable ]
 31  php7.3                   available    \
        [ =7.3.2  =7.3.3  =7.3.4  =7.3.6  =7.3.8  =7.3.9  =7.3.10
          =7.3.11  =7.3.13  =stable ]
 32  lustre2.10               available    \
        [ =2.10.5  =2.10.8  =stable ]
 33  java-openjdk11           available    [ =11  =stable ]
 34  lynis                    available    [ =stable ]
 35  kernel-ng                available    [ =stable ]
 36  BCC                      available    [ =0.x  =stable ]
 37  mono                     available    [ =5.x  =stable ]
 38  nginx1                   available    [ =stable ]
 39  ruby2.6                  available    [ =2.6  =stable ]
 40  mock                     available    [ =stable ]
 41  postgresql11             available    [ =11  =stable ]
 42  php7.4                   available    [ =stable ]
 43  livepatch                available    [ =stable ]
 44  python3.8                available    [ =stable ]
 45  haproxy2                 available    [ =stable ]
 46  collectd                 available    [ =stable ]
 47  aws-nitro-enclaves-cli   available    [ =stable ]
 48  R4                       available    [ =stable ]
  _  kernel-5.4               available    [ =stable ]
 50  selinux-ng               available    [ =stable ]
 51  php8.0                   available    [ =stable ]
 52  tomcat9                  available    [ =stable ]
 53  unbound1.13              available    [ =stable ]
 54  mariadb10.5              available    [ =stable ]
 55  kernel-5.10=latest       enabled      [ =stable ]
 56  redis6                   available    [ =stable ]
 57  ruby3.0                  available    [ =stable ]
 58  postgresql12             available    [ =stable ]
 59  postgresql13             available    [ =stable ]
 60  mock2                    available    [ =stable ]
 61  dnsmasq2.85              available    [ =stable ]
[root@ip-172-31-36-49 ec2-user]# yum-config-manager --enable epel
Failed to set locale, defaulting to C
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
=========================================== repo: epel ============================================
[epel]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/2
baseurl = 
cache = 0
cachedir = /var/cache/yum/x86_64/2/epel
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage = 
enabled = True
enablegroups = True
exclude = 
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/2/epel/gpgcadir
gpgcakey = 
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/2/epel/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
hdrdir = /var/cache/yum/x86_64/2/epel/headers
http_caching = all
includepkgs = 
ip_resolve = 
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid = 
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink = https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=x86_64
minrate = 0
mirrorlist = 
mirrorlist_expire = 86400
name = Extra Packages for Enterprise Linux 7 - x86_64
old_base_cache_dir = 
password = 
persistdir = /var/lib/yum/repos/x86_64/2/epel
pkgdir = /var/cache/yum/x86_64/2/epel/packages
priority = 99
proxy = False
proxy_dict = 
proxy_password = 
proxy_username = 
repo_gpgcheck = False
report_instanceid = False
retries = 7
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert = 
sslclientcert = 
sslclientkey = 
sslverify = True
throttle = 0
timeout = 5.0
ui_id = epel/x86_64
ui_repoid_vars = releasever,
   basearch
username =
[root@ip-172-31-36-49 ec2-user]# yum --enablerepo epel install ansible
Failed to set locale, defaulting to C
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
amzn2-core                                                                  | 3.7 kB  00:00:00     
amzn2extra-docker                                                           | 3.0 kB  00:00:00     
amzn2extra-epel                                                             | 3.0 kB  00:00:00     
amzn2extra-kernel-5.10                                                      | 3.0 kB  00:00:00     
epel/x86_64/metalink                                                        |  21 kB  00:00:00     
209 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package ansible.noarch 0:2.9.25-1.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================================================
 Package               Arch                 Version                       Repository          Size
===================================================================================================
Installing:
 ansible               noarch               2.9.25-1.el7                  epel                17 M
Transaction Summary
===================================================================================================
Install  1 Package
Total download size: 17 M
Installed size: 103 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/2/epel/packages/ansible-2.9.25-1.el7.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Public key for ansible-2.9.25-1.el7.noarch.rpm is not installed
ansible-2.9.25-1.el7.noarch.rpm                                             |  17 MB  00:00:03     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
 Userid     : "Fedora EPEL (7) <epel@fedoraproject.org>"
 Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 Package    : epel-release-7-11.noarch (@amzn2extra-epel)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : ansible-2.9.25-1.el7.noarch                                                     1/1 
  Verifying  : ansible-2.9.25-1.el7.noarch                                                     1/1
Installed:
  ansible.noarch 0:2.9.25-1.el7
Complete!
[root@ip-172-31-36-49 ec2-user]# ansible --version
ansible 2.9.25
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.18 (default, Jun 10 2021, 00:11:02) [GCC 7.3.1 20180712 (Red Hat 7.3.1-13)]
[root@ip-172-31-36-49 ec2-user]# rpm -qa | grep ansible
ansible-2.9.25-1.el7.noarch
[root@ip-172-31-36-49 ec2-user]#

EPEL after execution

# rpm -qa | grep ansible
ansible-2.9.25-1.el7.noarch

code with ❤️ in GitHub

See also: How to install Ansible in AlmaLinux 9 - Ansible install

Conclusion

Now you know how to install the latest version of Ansible in Amazon Linux using the Amazon Extras Library and EPEL repositories.

Related Articles

orchestrating containers via AnsibleNginx config templating with AnsibleIAM management via Ansible on AWS

See also: How to install Ansible in CentOS 8 Stream - Ansible install

See also

Ansible on Amazon Linux 2023 Automation Complete Guide

Category: installation

Watch the video: How to install Ansible in Amazon Linux 2 (AWS EC2) - Ansible install — Video Tutorial

Browse all Ansible tutorials · AnsiblePilot Home