安装ansible时报错(nothing provides (ansible-core >= 2.12.2 with ansible-core < 2.13) needed by ansible-5)

本文讲述了在 CentOS 8 上安装 ansible 时遇到版本过低错误的解决过程,通过删除官方源并配置本地 EPEL 源,最终成功安装了 ansible-2.9.27 版本。

基于centos8下载ansible时报版本过低错误

  • nothing provides (ansible-core >= 2.12.2 with ansible-core < 2.13) needed by ansible-5.4.0-3.el8.noarch
    (try to add ‘–skip-broken’ to skip uninstallable packages or ‘–nobest’ to use not only best candidate packages)

产生如下的报错原因

[root@localhost ~]# dnf -y install ansible
CentOS-8.5.2111 - Base - mirrors.aliyun.com       7.2 kB/s | 3.9 kB     00:00    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com     6.6 kB/s | 1.5 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com   23 kB/s | 4.3 kB     00:00    
Error: 
 Problem: cannot install the best candidate for the job
  - nothing provides (ansible-core >= 2.12.2 with ansible-core < 2.13) needed by ansible-5.4.0-3.el8.noarch
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

解决

这里是由于centos官方停更了,导致使用阿里云的epel源下载不了,需要使用本地的epel源来使用
//删除即可

[root@localhost yum.repos.d]# ls
CentOS-Base.repo            epel-modular.repo  epel-testing-modular.repo
 epel.repo          epel-testing.repo
[root@localhost yum.repos.d]# rm -rf epel*
//配置本地epel源
[root@localhost yum.repos.d]# dnf list all|grep ansible
ansible.noarch                                         2.9.27-1.el8                                           @centos-ansible-29
centos-release-ansible-29.noarch                       1-2.el8                                                @extras          
[root@localhost ~]# dnf -y install centos-release-ansible-29-1-2.el8.noarch
[root@localhost yum.repos.d]#  ls /etc/yum.repos.d/ |grep ansible
CentOS-SIG-ansible-29.repo

//在次下载
[root@localhost yum.repos.d]# dnf -y install ansible
....................
Installed:
  ansible-2.9.27-1.el8.noarch            python3-babel-2.5.1-7.el8.noarch        
  python3-cffi-1.11.5-5.el8.x86_64       python3-cryptography-3.2.1-5.el8.x86_64 
  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.el8.noarch            
  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.el8.x86_64               

Complete!

//查看版本完美解决
[root@localhost ~]# ansible --version
ansible 2.9.27
  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, Jan 19 2022, 23:28:49) [GCC 8.5.0 20210514 (Red Hat 8.5.0-7)]
### 安装指定版本的 AnsibleAnsible-Core 为了安装特定版本的 `ansible` 和 `ansible-core`,可以使用 `pip` 工具并明确指定所需的版本号。以下是实现此目标的具体方法: #### 使用 Pip 安装指定版本的 AnsibleAnsible-Core 运行以下命令以安装所需版本的软件包: ```bash sudo pip3 install ansible==7.7.0 ansible-core==2.14.1111.5 ``` 这一步骤会确保安装的是精确匹配的版本[^1]。 需要注意的是,在某些情况下可能会遇到依赖冲突问题。如果发生这种情况,则可能需要清理现有的安装或者创建一个新的虚拟环境来进行隔离处理[^2]。 另外,请确认已满足 Python 的最低需求版本;即至少为 Python 2.7 或者介于 Python 3.5 到 3.11 范围内的任意一个版本[^3]。 对于 CentOS 系统而言,推荐先更新系统的包管理器以及相关组件到最新状态后再执行上述操作[^4]。 #### 配置和安装 Docker 至所有节点 要利用 Ansible 来跨多个服务器部署服务(比如这里提到的 Docker),首先得设置好 SSH 密钥认证以便无密码访问各个远程主机,并定义 inventory 文件列出所有的受管设备。 接着编写 Playbook 实现自动化过程如下所示: ```yaml --- - name: Install and configure docker on all nodes hosts: all become: yes tasks: - name: Ensure epel-release is installed (for RHEL/CentOS based systems) yum: name: epel-release state: present - name: Add Docker repository get_url: url: https://download.docker.com/linux/centos/docker-ce.repo dest: /etc/yum.repos.d/docker-ce.repo - name: Update cache after adding new repo command: dnf makecache fast - name: Install Docker Engine & CLI tools package: name: - docker-ce - docker-ce-cli - containerd.io state: latest - name: Start the service and enable it at boot time systemd: name: docker enabled: true started: true - name: Verify installation by running hello-world image once shell: | docker run --rm hello-world ``` 以上脚本涵盖了从准备阶段直到验证最终成果整个流程中的每一步动作描述清楚明了便于理解执行。 最后记得测试 playbook 是否正常运作再正式投入使用前最好做一次完整的 dry-run 测试!
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值