yum安装ansible报错如何解决

简介: 本篇内容记录了yum安装ansible报错的解决方案。

文章参考:https://mirrors.tuna.tsinghua.edu.cn/help/epel/


前言:安装ansible出现如下错误:


Error: Package: python-paramiko-2.1.1-0.10.el7.noarch (epel)
           Requires: python-cryptography
Error: Package: ansible-2.9.21-1.el7.noarch (epel)
           Requires: python-six
Error: Package: ansible-2.9.21-1.el7.noarch (epel)
           Requires: PyYAML
Error: Package: python-paramiko-2.1.1-0.10.el7.noarch (epel)
           Requires: python2-pyasn1
Error: Package: ansible-2.9.21-1.el7.noarch (epel)
           Requires: python2-cryptography
Error: Package: ansible-2.9.21-1.el7.noarch (epel)
           Requires: python-jinja2
Error: Package: ansible-2.9.21-1.el7.noarch (epel)
           Requires: python-setuptools
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest


一、报错信息:


[root@ansible ~]# yum install -y ansible
Loaded plugins: fastestmirror
Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * epel: mirrors.tuna.tsinghua.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package ansible.noarch 0:2.9.21-1.el7 will be installed
--> Processing Dependency: PyYAML for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: python-httplib2 for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: python-jinja2 for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: python-paramiko for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: python-setuptools for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: python-six for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: python2-cryptography for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: python2-jmespath for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: sshpass for package: ansible-2.9.21-1.el7.noarch
--> Running transaction check
---> Package ansible.noarch 0:2.9.21-1.el7 will be installed
--> Processing Dependency: PyYAML for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: python-jinja2 for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: python-setuptools for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: python-six for package: ansible-2.9.21-1.el7.noarch
--> Processing Dependency: python2-cryptography for package: ansible-2.9.21-1.el7.noarch
---> Package python-paramiko.noarch 0:2.1.1-0.10.el7 will be installed
--> Processing Dependency: python-cryptography for package: python-paramiko-2.1.1-0.10.el7.noarch
--> Processing Dependency: python2-pyasn1 for package: python-paramiko-2.1.1-0.10.el7.noarch
---> Package python2-httplib2.noarch 0:0.18.1-3.el7 will be installed
---> Package python2-jmespath.noarch 0:0.9.4-2.el7 will be installed
---> Package sshpass.x86_64 0:1.06-1.el7 will be installed
--> Finished Dependency Resolution
Error: Package: python-paramiko-2.1.1-0.10.el7.noarch (epel)
           Requires: python-cryptography
Error: Package: ansible-2.9.21-1.el7.noarch (epel)
           Requires: python-six
Error: Package: ansible-2.9.21-1.el7.noarch (epel)
           Requires: PyYAML
Error: Package: python-paramiko-2.1.1-0.10.el7.noarch (epel)
           Requires: python2-pyasn1
Error: Package: ansible-2.9.21-1.el7.noarch (epel)
           Requires: python2-cryptography
Error: Package: ansible-2.9.21-1.el7.noarch (epel)
           Requires: python-jinja2
Error: Package: ansible-2.9.21-1.el7.noarch (epel)
           Requires: python-setuptools
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest


二、如何解决


1、重装虚拟机


重装一台虚拟机,保证虚拟机可以上网,可以选择桥接模式网卡


微信图片_20220510122932.png


2、修改yum源


建议先备份 /etc/yum.repos.d/ 内的文件(CentOS 7 及之前为 CentOS-Base.repo,CentOS 8 为CentOS-Linux-*.repo)


然后编辑 /etc/yum.repos.d/ 中的相应文件,在 mirrorlist= 开头行前面加 # 注释掉;并将 baseurl= 开头行取消注释(如果被注释的话),把该行内的域名(例如mirror.centos.org)替换为 mirrors.tuna.tsinghua.edu.cn。


以上步骤可以被下方的命令一步完成


sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo


注意其中的*通配符,如果只需要替换一些文件中的源,请自行增删。


注意,如果需要启用其中一些 repo,需要将其中的 enabled=0 改为 enabled=1。


最后,更新软件包缓存


sudo yum makecache


3、使用EPEL源


yum install epel-release
当前tuna已经在epel的官方镜像列表里,所以不需要其他配置,mirrorlist机制就能让你的服务器就近使用tuna的镜像。如果你想强制 你的服务器使用tuna的镜像,可以修改/etc/yum.repos.d/epel.repo,将mirrorlist和metalink开头的行注释掉。
接下来,取消注释这个文件里baseurl开头的行,并将其中的http://download.fedoraproject.org/pub替换成https://mirrors.tuna.tsinghua.edu.cn。
可以用如下命令自动替换:(来自 https://github.com/tuna/issues/issues/687)
sed -e 's!^metalink=!#metalink=!g' \
    -e 's!^#baseurl=!baseurl=!g' \
    -e 's!//download\.fedoraproject\.org/pub!//mirrors.tuna.tsinghua.edu.cn!g' \
    -e 's!http://mirrors\.tuna!https://mirrors.tuna!g' \
    -i /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo


4、安装ansible


yum install -y ansible
.....
Dependency Installed:
  PyYAML.x86_64 0:3.10-11.el7                                                            
  libyaml.x86_64 0:0.1.4-11.el7_0                                                        
  python-babel.noarch 0:0.9.6-8.el7                                                      
  python-backports.x86_64 0:1.0-8.el7                                                    
  python-backports-ssl_match_hostname.noarch 0:3.5.0.1-1.el7                             
  python-cffi.x86_64 0:1.6.0-5.el7                                                       
  python-enum34.noarch 0:1.0.4-1.el7                                                     
  python-idna.noarch 0:2.4-1.el7                                                         
  python-ipaddress.noarch 0:1.0.16-2.el7                                                 
  python-jinja2.noarch 0:2.7.2-4.el7                                                     
  python-markupsafe.x86_64 0:0.11-10.el7                                                 
  python-paramiko.noarch 0:2.1.1-9.el7                                                   
  python-ply.noarch 0:3.4-11.el7                                                         
  python-pycparser.noarch 0:2.14-1.el7                                                   
  python-setuptools.noarch 0:0.9.8-7.el7                                                 
  python-six.noarch 0:1.9.0-2.el7                                                        
  python2-cryptography.x86_64 0:1.7.2-2.el7                                              
  python2-httplib2.noarch 0:0.18.1-3.el7                                                 
  python2-jmespath.noarch 0:0.9.4-2.el7                                                  
  python2-pyasn1.noarch 0:0.1.9-7.el7                                                    
  sshpass.x86_64 0:1.06-2.el7                                                            
Complete!


5、测试


[root@localhost ~]# ansible --version
ansible 2.9.21
  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 = /usr/bin/ansible
  python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]


相关文章
|
15天前
|
Linux C语言
linux yum安装ffmpeg 图文详解
linux yum安装ffmpeg 图文详解
35 0
|
15天前
|
Linux
linux yum 安装rar和unrar
linux yum 安装rar和unrar
50 0
|
1天前
|
存储 运维 Shell
Ansible自动化运维工具安装和基本使用
Ansible 是一款无代理的IT自动化工具,通过SSH连接目标主机执行配置管理、应用部署和云端管理任务。它使用YAML编写的Playbook定义任务,核心组件包括Playbook、模块、主机清单、变量等。Ansible的优势在于易用、功能强大、无须在目标主机安装额外软件,并且开源。安装过程涉及配置网络源、yum安装和SSH密钥设置。通过定义主机清单和使用模块进行通信测试,确保连接成功。
Ansible自动化运维工具安装和基本使用
|
1天前
|
Linux
centos 6.5安装yum
centos 6.5安装yum
12 0
|
3天前
|
存储 Linux 网络安全
centos7使用yum网络安装
这些是使用Yum进行网络安装的基本步骤。根据你的需求,你可以重复步骤3和4来安装其他软件包。请注意,执行Yum操作需要root或具有sudo权限的用户。
15 1
|
6天前
|
应用服务中间件 nginx
yum 安装报错 No package nginx available Error:Nothing to do
yum 安装报错 No package nginx available Error:Nothing to do
17 1
|
15天前
|
关系型数据库 MySQL Linux
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
CentOS 7 下使用yum安装MySQL5.7.20 最简单 图文详解
72 0
|
27天前
|
Linux
Linux: yum查看、安装、删除软件包
Linux: yum查看、安装、删除软件包
30 0
|
2月前
|
Linux Shell
Linux:centos yum安装指令指南
Linux:centos yum安装指令指南
173 0
Linux:centos yum安装指令指南
|
3月前
yum 报错:Another app is currently holding the yum lock; waiting for it to exit
开发过程中需要用到 yum 命令 有时候执行 yum 会报错如下
18 0