RHEL8安装ansible报错

RHEL8安装ansible报错
系统版本

[root@linuxprobe cdrom]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.0 (Ootpa)
[root@linuxprobe cdrom]# 

创建软件仓库

[root@linuxprobe cdrom]# cat /etc/yum.repos.d/redhat.repo 
#
# Certificate-Based Repositories
# Managed by (rhsm) subscription-manager
#
# *** This file is auto-generated.  Changes made here will be over-written. ***
# *** Use "subscription-manager repo-override --help" if you wish to make changes. ***
#
# If this file is empty and this system is subscribed consider
# a "yum repolist" to refresh available repos
#
[BaseOS]
name=BaseOS
baseurl=file:///media/cdrom/BaseOS
enabled=1
gpgcheck=0

[AppStream]
name=AppStream
baseurl=file:///media/cdrom/AppStream
enabled=1
gpgcheck=0

[EPEL]
name=EPEL
baseurl=https://dl.fedoraproject.org/pub/epel/8/Everything/x86_64/
enabled=1
gpgcheck=0


安装ansible结果报错


[root@linuxprobe cdrom]# dnf install -y ansible
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:02:35 ago on Wed 21 Dec 2022 06:13:32 AM CST.
Error: 
 Problem: conflicting requests
  - nothing provides python(abi) = 3.9 needed by ansible-6.3.0-1.el8.noarch
  - nothing provides (python3.9dist(ansible-core) >= 2.13.3 with python3.9dist(ansible-core) < 2.14) needed by ansible-6.3.0-1.el8.noarch
  - nothing provides /usr/bin/python3.9 needed by ansible-6.3.0-1.el8.noarch
  - nothing provides python3.9dist(ansible-core) needed by ansible-6.3.0-1.el8.noarch
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)


查看python版本

[root@linuxprobe cdrom]# python3 --version
Python 3.6.8

直接下载ansible2.9.18版本,包中所含内容

[root@linuxprobe cdrom]# ls
ansible-2.9.18-1.el7.noarch.rpm                               python-idna-2.4-1.el7.noarch.rpm
libyaml-0.1.4-11.el7_0.x86_64.rpm                             python-ipaddress-1.0.16-2.el7.noarch.rpm
python2-cryptography-1.7.2-2.el7.x86_64.rpm                   python-jinja2-2.7.2-4.el7.noarch.rpm
python2-httplib2-0.18.1-3.el7.noarch.rpm                      python-markupsafe-0.11-10.el7.x86_64.rpm
python2-jmespath-0.9.4-2.el7.noarch.rpm                       python-paramiko-2.1.1-9.el7.noarch.rpm
python2-pyasn1-0.1.9-7.el7.noarch.rpm                         python-ply-3.4-11.el7.noarch.rpm
python-babel-0.9.6-8.el7.noarch.rpm                           python-pycparser-2.14-1.el7.noarch.rpm
python-backports-1.0-8.el7.x86_64.rpm                         python-setuptools-0.9.8-7.el7.noarch.rpm
python-backports-ssl_match_hostname-3.5.0.1-1.el7.noarch.rpm  python-six-1.9.0-2.el7.noarch.rpm
python-cffi-1.6.0-5.el7.x86_64.rpm                            PyYAML-3.10-11.el7.x86_64.rpm
python-enum34-1.0.4-1.el7.noarch.rpm                          sshpass-1.06-1.el7.x86_64.rpm


安装包中rpm
[root@linuxprobe cdrom]# rpm -Uvh --force --nodeps *
warning: ansible-2.9.18-1.el7.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
warning: libyaml-0.1.4-11.el7_0.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:python-six-1.9.0-2.el7           ################################# [  4%]
   2:python-ipaddress-1.0.16-2.el7    ################################# [  9%]
   3:python2-pyasn1-0.1.9-7.el7       ################################# [ 13%]
   4:sshpass-1.06-1.el7               ################################# [ 17%]
   5:python-ply-3.4-11.el7            ################################# [ 22%]
   6:python-pycparser-2.14-1.el7      ################################# [ 26%]
   7:python-cffi-1.6.0-5.el7          ################################# [ 30%]
   8:python-markupsafe-0.11-10.el7    ################################# [ 35%]
   9:python-idna-2.4-1.el7            ################################# [ 39%]
  10:python-enum34-1.0.4-1.el7        ################################# [ 43%]
  11:python-backports-1.0-8.el7       ################################# [ 48%]
  12:python-backports-ssl_match_hostna################################# [ 52%]
  13:python-setuptools-0.9.8-7.el7    ################################# [ 57%]
  14:python2-cryptography-1.7.2-2.el7 ################################# [ 61%]
  15:python-paramiko-2.1.1-9.el7      ################################# [ 65%]
  16:python-babel-0.9.6-8.el7         ################################# [ 70%]
  17:python-jinja2-2.7.2-4.el7        ################################# [ 74%]
  18:python2-jmespath-0.9.4-2.el7     ################################# [ 78%]
  19:python2-httplib2-0.18.1-3.el7    ################################# [ 83%]
  20:libyaml-0.1.4-11.el7_0           ################################# [ 87%]
  21:PyYAML-3.10-11.el7               ################################# [ 91%]
  22:ansible-2.9.18-1.el7             ################################# [ 96%]
Cleaning up / removing...
  23:libyaml-0.1.7-5.el8              ################################# [100%]
[root@linuxprobe cdrom]# ansible --version
bash: /usr/bin/ansible: /usr/bin/python2: bad interpreter: No such file or directory


安装完后还是无法使用,请问该怎么解决

你安装的python3,但是默认ansible的依赖python2这个应该在你的bin下没有,因为你安装方式加了 --force强制忽略了依赖,我一般现在很少这么干。
先说解决办法:先去找到你的python2的路径,之后创建软连接在bin下

cd /usr/bin
sudo ln -fs <你的python2的完整路径> python2