If you are using RHEL 8 then you can use the subscription manager to get Ansible with the host and config file pre-built.
Also, you will need to create an account on https://developers.redhat.com before you can do this:
subscription-manager register --auto-attach
subscription-manager repos --enable ansible-2.8-for-rhel-8-x86_64-rpms
yum -y install ansible
ansible --version
Answer from Aryan Srivastava on Stack OverflowVideos
If you are using RHEL 8 then you can use the subscription manager to get Ansible with the host and config file pre-built.
Also, you will need to create an account on https://developers.redhat.com before you can do this:
subscription-manager register --auto-attach
subscription-manager repos --enable ansible-2.8-for-rhel-8-x86_64-rpms
yum -y install ansible
ansible --version
EPEL8 is not released yet. There are some packages available, but a lot are still being worked on and the repo is not considered "generally available".
For now, you can install Ansible from the Python Package Index (PyPI):
yum install python3-pip
pip3 install ansible
The solutions for that I have created a small script it changes centos-repos and install epel-relase then changes epel's repo and install Ansible 2.9.27-1.el8 with all dependencies.
#!/bin/bash
set -ex
# Add EPEL repository
osV=$(rpm --eval '%{centos_ver}')
if [ "$osV" == "8" ]; then
cd /etc/yum.repos.d/
sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
sudo yum install -y epel-release
sudo sed -i 's/metalink/#metalink/g' /etc/yum.repos.d/epel*
sudo sed -i 's|#baseurl=https://download.example/pub/|baseurl=https://mirror.init7.net/fedora/|g' /etc/yum.repos.d/epel*
else
sudo yum install -y epel-release
fi
sudo yum install -y ansible
I also stucked by this question,and centos version was 8.5.2111 (not centos stream)
and i just manually download ansible-core.rpm and it's dependency and install them,
then i can install the ansible by dnf install ansible
the detail step was:
wget http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/ansible-core-2.12.2-3.el8.x86_64.rpm
wget http://mirror.centos.org/centos/8-stream/AppStream/aarch64/os/Packages/python38-resolvelib-0.5.4-5.el8.noarch.rpm
wget http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/sshpass-1.09-4.el8.x86_64.rpm
rpm -ivh python38-resolvelib-0.5.4-5.el8.noarch.rpm
rpm -ivh sshpass-1.09-4.el8.x86_64.rpm
rpm -ivh ansible-core-2.12.2-3.el8.x86_64.rpm