CentOS8.5
# cat /etc/redhat-release
CentOS Linux release 8.5.2111
# uname -a
Linux localhost.localdomain 4.18.0-348.el8.x86_64 #1 SMP Tue Oct 19 15:14:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
在 CentOS 8 中安装软件出现 “错误:为仓库 ‘appstream’ 下载元数据失败” 的解决办法
出现这个错误提示的原因是在2022年1月31日,CentOS 团队从官方镜像中移除 CentOS 8 的所有包。
因为 CentOS 8 已于2021年12月31日停止官方服务了,但软件包仍在官方镜像上保留了一段时间,现在他们被转移到 https://vault.centos.org。
如果你仍然需要运行 CentOS 8,你可以在 /etc/yum.repos.d 中更新一下源,使用 vault.centos.org 代替 mirror.centos.org 即可。
sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
# yum -y install epel-release
# yum list ansible* --showduplicates | sort -r
ansible-srpm-macros.noarch 1-12.el8 epel
ansible-pcp.noarch 2.2.1-1.el8 appstream
ansible-packaging.noarch 1-12.el8 epel
ansible.noarch 9.2.0-1.el8 epel
ansible-freeipa-tests.noarch 0.3.8-1.el8 appstream
ansible-freeipa.noarch 0.3.8-1.el8 appstream
ansible-collection-redhat-rhel_mgmt.noarch 1.0.0-2.el8 appstream
ansible-collection-netbox-netbox.noarch 3.7.1-1.el8 epel
ansible-collection-microsoft-sql.noarch 1.1.0-1.el8 appstream
ansible-collection-containers-podman.noarch 1.12.0-5.el8 epel
ansible-collection-community-rabbitmq.noarch 1.2.3-1.el8 epel
ansible-collection-community-mysql.noarch 3.5.1-1.el8 epel
ansible-collection-community-libvirt.noarch 1.2.0-1.el8 epel
ansible-collection-community-general.noarch 7.0.0-1.el8 epel
ansible-collection-community-docker.noarch 2.6.0-1.el8 epel
ansible-collection-chocolatey-chocolatey.noarch 1.4.0-1.el8 epel
ansible-collection-awx-awx.noarch 24.3.1-1.el8 epel
ansible-collection-ansible-utils.noarch 2.6.1-1.el8 epel
ansible-collection-ansible-posix.noarch 1.5.4-1.el8 epel
# yum info ansible
上次元数据过期检查:0:20:02 前,执行于 2024年06月05日 星期三 08时00分31秒。
可安装的软件包
名称 : ansible
版本 : 9.2.0
发布 : 1.el8
架构 : noarch
大小 : 46 M
源 : ansible-9.2.0-1.el8.src.rpm
仓库 : epel
概况 : Curated set of Ansible collections included in addition to ansible-core
URL : https://ansible.com
协议 : GPL-3.0-or-later AND Apache-2.0 AND BSD-2-Clause AND BSD-3-Clause AND MIT AND MPL-2.0 AND PSF-2.0
描述 : Ansible is a radically simple model-driven configuration management,
: multi-node deployment, and remote task execution system. Ansible works
: over SSH and does not require any software or daemons to be installed
: on remote nodes. Extension modules can be written in any language and
: are transferred to managed machines automatically.
:
: This package provides a curated set of Ansible collections included in addition
: to ansible-core.
可以看出,CentOS8.5 上默认仓库中ansible版本是比较高的,注意基于低版本ansible编写的playbook可能用这个就跑不了!
如何在CentOS8.x上安装ansible2.x?
CentOS8 使用 platform-python 为系统创建了一个隔离的python环境,yum就是使用的 platform-python 提供的python。
# which yum
/usr/bin/yum
# ls -l /usr/bin/yum
lrwxrwxrwx. 1 root root 5 9月 18 2021 /usr/bin/yum -> dnf-3
# ls -l /usr/bin/dnf-3
-rwxr-xr-x. 1 root root 1954 9月 18 2021 /usr/bin/dnf-3
# cat /usr/bin/yum
#-------------------------------------------------#
#!/usr/libexec/platform-python
# The dnf executable script.
#
# Copyright (C) 2012-2016 Red Hat, Inc.
#
#-------------------------------------------------#
# py
pydoc3.6 pyvenv-3.6
# rpm -qf /usr/bin/pyvenv-3.6
platform-python-3.6.8-41.el8.x86_64
# rpm -qf /usr/bin/pydoc3.6
platform-python-3.6.8-41.el8.x86_64
# yum info platform-python
上次元数据过期检查:0:04:13 前,执行于 2024年06月05日 星期三 07时44分41秒。
已安装的软件包
名称 : platform-python
版本 : 3.6.8
发布 : 41.el8
架构 : x86_64
大小 : 40 k
源 : python3-3.6.8-41.el8.src.rpm
仓库 : @System
来自仓库 : anaconda
概况 : Internal interpreter of the Python programming language
URL : https://www.python.org/
协议 : Python
描述 : This is the internal interpreter of the Python language for the system.
: To use Python yourself, please install one of the available Python 3 packages,
: for example python36.
可安装的软件包
名称 : platform-python
版本 : 3.6.8
发布 : 41.el8
架构 : i686
大小 : 85 k
源 : python3-3.6.8-41.el8.src.rpm
仓库 : appstream
概况 : Internal interpreter of the Python programming language
URL : https://www.python.org/
协议 : Python
描述 : This is the internal interpreter of the Python language for the system.
: To use Python yourself, please install one of the available Python 3 packages,
: for example python36.
在 CentOS 8 上,其他应用程序所需的 Python 默认没有被安装,需要自定义安装!
// CentOS8.5 安装python3
# yum -y install python36
// CentOS8.5 安装python2
# yum -y install python2
# alternatives --config python
共有 3 个提供“python”的程序。
选项 命令
-----------------------------------------------
*+ 1 /usr/libexec/no-python
2 /usr/bin/python3
3 /usr/bin/python2
按 Enter 保留当前选项[+],或者键入选项编号:
# rpm -qf /usr/libexec/no-python
platform-python-3.6.8-41.el8.x86_64
# rpm -qf /usr/bin/python3
python36-3.6.8-38.module_el8.5.0+895+a459eca8.x86_64
# rpm -qf /usr/bin/python2
python2-2.7.18-7.module_el8.5.0+894+1c54b371.x86_64
// centos-release-ansible
https://rockylinux.pkgs.org/8/rockylinux-extras-x86_64/
https://rockylinux.pkgs.org/8/rockylinux-extras-x86_64/centos-release-ansible.html
# wget https://dl.rockylinux.org/pub/rocky/8/extras/x86_64/os/Packages/c/centos-release-ansible-29-1-2.el8.noarch.rpm
# yum -y localinstall centos-release-ansible-29-1-2.el8.noarch.rpm
# rpm -ql centos-release-ansible-29-1-2.el8.noarch
/etc/yum.repos.d/CentOS-SIG-ansible-29.repo
# sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
# sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
# yum list ansible --showduplicates | sort -r
CentOS Linux 8 - Extras 1.8 kB/s | 1.5 kB 00:00
CentOS Linux 8 - BaseOS 4.3 kB/s | 3.9 kB 00:00
CentOS Linux 8 - AppStream 5.1 kB/s | 4.3 kB 00:00
CentOS Configmanagement SIG - ansible-29 767 kB/s | 2.1 MB 00:02
ansible.noarch 9.2.0-1.el8 epel
ansible.noarch 2.9.9-2.el8 centos-ansible-29
ansible.noarch 2.9.9-1.el8 centos-ansible-29
ansible.noarch 2.9.8-1.el8 centos-ansible-29
ansible.noarch 2.9.7-1.el8 centos-ansible-29
ansible.noarch 2.9.6-2.el8 centos-ansible-29
ansible.noarch 2.9.27-1.el8 centos-ansible-29
ansible.noarch 2.9.25-1.el8 centos-ansible-29
ansible.noarch 2.9.24-1.el8 centos-ansible-29
ansible.noarch 2.9.23-1.el8 centos-ansible-29
ansible.noarch 2.9.22-1.el8 centos-ansible-29
ansible.noarch 2.9.21-1.el8 centos-ansible-29
ansible.noarch 2.9.20-1.el8 centos-ansible-29
ansible.noarch 2.9.19-1.el8 centos-ansible-29
ansible.noarch 2.9.18-1.el8 centos-ansible-29
ansible.noarch 2.9.17-2.el8 centos-ansible-29
ansible.noarch 2.9.17-1.el8 centos-ansible-29
ansible.noarch 2.9.16-1.el8 centos-ansible-29
ansible.noarch 2.9.15-1.el8 centos-ansible-29
ansible.noarch 2.9.14-1.el8 centos-ansible-29
ansible.noarch 2.9.13-1.el8 centos-ansible-29
ansible.noarch 2.9.12-1.el8 centos-ansible-29
ansible.noarch 2.9.11-1.el8 centos-ansible-29
ansible.noarch 2.9.10-2.el8 centos-ansible-29
# yum -y install ansible-2.9.14
上次元数据过期检查:0:04:52 前,执行于 2024年06月05日 星期三 18时44分24秒。
依赖关系解决。
======================================================================================================================================
软件包 架构 版本 仓库
======================================================================================================================================
安装:
ansible noarch 2.9.14-1.el8 centos-ansible-29
安装依赖关系:
python3-babel noarch 2.5.1-7.el8 appstream
python3-cffi x86_64 1.11.5-5.el8 baseos
python3-cryptography x86_64 3.2.1-5.el8 baseos
python3-jinja2 noarch 2.10.1-3.el8 appstream
python3-markupsafe x86_64 0.23-19.el8 appstream
python3-ply noarch 3.9-9.el8 baseos
python3-pycparser noarch 2.14-14.el8 baseos
python3-pytz noarch 2017.2-9.el8 appstream
python3-pyyaml x86_64 3.12-12.el8 baseos
sshpass x86_64 1.06-8.el8 centos-ansible-29
安装弱的依赖:
python3-jmespath noarch 0.9.0-11.el8 appstream
事务概要
======================================================================================================================================
安装 12 软件包
总下载:24 M
安装大小:124 M
下载软件包:
(1/12): python3-jmespath-0.9.0-11.el8.noarch.rpm 43 kB/s
(2/12): python3-markupsafe-0.23-19.el8.x86_64.rpm 105 kB/s
(3/12): python3-jinja2-2.10.1-3.el8.noarch.rpm 357 kB/s
(4/12): python3-pytz-2017.2-9.el8.noarch.rpm 153 kB/s
(5/12): python3-cffi-1.11.5-5.el8.x86_64.rpm 318 kB/s
(6/12): python3-babel-2.5.1-7.el8.noarch.rpm 2.0 MB/s
(7/12): python3-ply-3.9-9.el8.noarch.rpm 304 kB/s
(8/12): python3-cryptography-3.2.1-5.el8.x86_64.rpm 631 kB/s
(9/12): python3-pycparser-2.14-14.el8.noarch.rpm 339 kB/s
(10/12): python3-pyyaml-3.12-12.el8.x86_64.rpm 554 kB/s
(11/12): sshpass-1.06-8.el8.x86_64.rpm 81 kB/s
(12/12): ansible-2.9.14-1.el8.noarch.rpm 6.1 MB/s
--------------------------------------------------------------------------------------------------------------------------------------
总计 4.3 MB/s
CentOS Configmanagement SIG - ansible-29 1.0 MB/s
导入 GPG 公钥 0x6E8B7E8A:
Userid: "CentOS Config Management SIG (https://wiki.centos.org/SpecialInterestGroup/ConfigManagementSIG) <security@centos.org>"
指纹: C75A FB57 D5C0 F238 CB15 BEC8 1AE1 10FA 6E8B 7E8A
来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-ConfigManagement
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 :
安装 : sshpass-1.06-8.el8.x86_64
安装 : python3-pyyaml-3.12-12.el8.x86_64
安装 : python3-ply-3.9-9.el8.noarch
安装 : python3-pycparser-2.14-14.el8.noarch
安装 : python3-cffi-1.11.5-5.el8.x86_64
安装 : python3-cryptography-3.2.1-5.el8.x86_64
安装 : python3-pytz-2017.2-9.el8.noarch
安装 : python3-babel-2.5.1-7.el8.noarch
安装 : python3-markupsafe-0.23-19.el8.x86_64
安装 : python3-jinja2-2.10.1-3.el8.noarch
安装 : python3-jmespath-0.9.0-11.el8.noarch
安装 : ansible-2.9.14-1.el8.noarch
运行脚本: ansible-2.9.14-1.el8.noarch
验证 : python3-babel-2.5.1-7.el8.noarch
验证 : python3-jinja2-2.10.1-3.el8.noarch
验证 : python3-jmespath-0.9.0-11.el8.noarch
验证 : python3-markupsafe-0.23-19.el8.x86_64
验证 : python3-pytz-2017.2-9.el8.noarch
验证 : python3-cffi-1.11.5-5.el8.x86_64
验证 : python3-cryptography-3.2.1-5.el8.x86_64
验证 : python3-ply-3.9-9.el8.noarch
验证 : python3-pycparser-2.14-14.el8.noarch
验证 : python3-pyyaml-3.12-12.el8.x86_64
验证 : ansible-2.9.14-1.el8.noarch
验证 : sshpass-1.06-8.el8.x86_64
已安装:
ansible-2.9.14-1.el8.noarch python3-babel-2.5.1-7.el8.noarch python3-cffi-1.11.5-5.el8.x86_64 python3-cryptogra
python3-jinja2-2.10.1-3.el8.noarch python3-jmespath-0.9.0-11.el8.noarch python3-markupsafe-0.23-19.el8.x86_64 python3-ply-3.9-9
python3-pycparser-2.14-14.el8.noarch python3-pytz-2017.2-9.el8.noarch python3-pyyaml-3.12-12.el8.x86_64 sshpass-1.06-8.el
完毕!
# ansible --version
ansible 2.9.14
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, Sep 10 2021, 09:13:53) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
# ansible 127.0.0.1 -m shell -a 'date'
127.0.0.1 | CHANGED | rc=0 >>
2024年 06月 05日 星期三 18:50:12 CST
参考
在 CentOS 8 中安装软件出现 “错误:为仓库 ‘appstream’ 下载元数据失败” 的解决办法
https://www.hhyit.com/archives/4226
如何在 CentOS 8 上安装 Python
https://cloud.tencent.com/developer/article/1626845
centos-release-ansible
https://rockylinux.pkgs.org/8/rockylinux-extras-x86_64/
https://rockylinux.pkgs.org/8/rockylinux-extras-x86_64/centos-release-ansible.html
CentOS8系统下alternatives命令的用法
https://mp.weixin.qq.com/s/YQju-vk57znToIU4lYhfqQ
Linux:使用 Alternatives 管理多版本程序
https://mp.weixin.qq.com/s/TW-x_WrLIGwwhfrudxG3vw
网友评论