yum install ansible无法直接安装Ansible的解决方法

简介: 准备三台机器:server.example.comnode1.example.comnode2.example.com配置IP,主机名,/etc/hosts

前言


一、准备三台机器配置IP主机名

准备三台机器:

server.example.com

node1.example.com

node2.example.com

配置IP,主机名,/etc/hosts

[root@server ~]# vim /etc/hosts
配置IP 主机名
192.168.193.129 server.explame.com
192.168.193.134 a1.explame.com
192.168.193.135 a2.explame.com

二、设置免密登录

然后去配置免密登录

[root@BBB ~]# ssh-keygen -t rsa  ---指定加密算法
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
---保存私钥的文件全路径
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:wkC11BzXR/Ccvs3IQvDhIOz7UhhRE35pYAvhHcZUDgY root@BBB
The key's randomart image is:
+---[RSA 3072]----+
|    ..ooEB&+oo.  |
|   . . ++O.B.+.. |
|    . . +.* *.+  |
|     o ... B o   |
|      o So  + .  |
|       ..... . = |
|        ..  . + o|
|        ..   .   |
|         ..      |
+----[SHA256]-----+
默认的证书目录:/root/.ssh
默认创建的公钥文件:/root/.ssh/id_rsa.pub
在保存私钥的文件全路径的目录下生成密钥对
[root@BBB ~]# ll /root/.ssh/
total 8
-rw-------. 1 root root 2590 Jul 28 23:21 id_rsa
-rw-r--r--. 1 root root  562 Jul 28 23:21 id_rsa.pub
然后将公钥追加到192.168.193.134这个服务器上的~/.ssh/authorized_keys文件
1、将公钥通过scp拷贝到服务器上,然后追加到~/.ssh/authorized_keys文件中。scp -P 22 ~/.ssh/id_rsa.pub user@host:~/。
2、通过ssh-copy-id程序,ssh-copyid user@host
3、可以通过cat ~/.ssh/id_rsa.pub | ssh -p 22 user@host ‘cat >> ~/.ssh/authorized_keys’,这个可以更改端口号。
如果另外一台服务器没有.ssh目录
输入# ssh localhost
 .ssh 是记录密码信息的文件夹,如果没有登录过root的话,就没有 .ssh 文件夹,因此登录 localhost ,并输入密码就会生成了。
.ssh目录的权限为700,其下文件authorized_keys和私钥的权限为600。否则会因为权限问题导致无法免密码登录。我们可以看到登陆后会有known_hosts文件生成。
最后通过ssh root@192.168.193.134验证

三、安装ansible

安装ansible出现的问题

Error:

Problem: conflicting requests


   ●  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@a2 ~]# yum install -y ansible
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Repository AppStream is listed more than once in the configuration
Last metadata expiration check: 2:28:10 ago on Tue 02 Aug 2022 03:07:37 PM CST.
Error: 
 Problem: conflicting requests
  - 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)

出现的问题的原因是

yum源里面的版本低必须是2.12以上的

更换yum源

配置yum源使用Centos-stream.repo

上传到 /etc/yum.repos.d/目录

下载链接Centos-stream.repo

然后清理缓存

yum clean all

yum makecahe

等待安装

使用ansible --version去验证

[root@server ~]# ansible --version
ansible [core 2.12.7]
  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.8/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.13 (default, Jun 24 2022, 15:27:57) [GCC 8.5.0 20210514 (Red Hat 8.5.0-13)]
  jinja version = 2.11.3
  libyaml = True

配置清单:/etc/ansible/hosts

在这里面配置

[A]
a1.example.com
a2.example.com

使用ansible node -m ping去验证

[root@server ~]# ansible A -m ping
a1.explame.com | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
a2.explame.com | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}


目录
打赏
0
0
0
0
1
分享
相关文章
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
234 25
|
2月前
|
yum install -y net-snmp-devel 安装不成功 zabbix项目安装,Errors during downloading metadata for repository ‘extras-common’:问题解决方案-优雅草卓伊凡
yum install -y net-snmp-devel 安装不成功 zabbix项目安装,Errors during downloading metadata for repository ‘extras-common’:问题解决方案-优雅草卓伊凡
82 13
yum install -y net-snmp-devel 安装不成功 zabbix项目安装,Errors during downloading metadata for repository ‘extras-common’:问题解决方案-优雅草卓伊凡
【Linux】另一种基于rpm安装yum的方式
通过本文的方法,您可以在离线环境中使用RPM包安装YUM并进行必要的配置。这种方法适用于无法直接访问互联网的服务器或需要严格控制软件源的环境。通过配置本地YUM仓库,确保了软件包的安装和更新可以顺利进行。希望本文能够为您在特定环境中部署YUM提供实用的指导。
494 0
Linux 安装 mysql【使用yum源进行安装】
这篇文章介绍了在Linux系统中使用yum源安装MySQL数据库的步骤,包括配置yum源、安装MySQL服务、启动服务以及修改root用户的默认密码。
Linux 安装 mysql【使用yum源进行安装】
Linux 使用Yum安装Go和配置环境
Linux 使用Yum安装Go和配置环境
自动化运维的新篇章:使用Ansible进行服务器配置管理
【10月更文挑战第34天】在现代IT基础设施的快速迭代中,自动化运维成为提升效率、确保一致性的关键手段。本文将通过介绍Ansible工具的使用,展示如何实现高效的服务器配置管理。从基础安装到高级应用,我们将一步步揭开自动化运维的神秘面纱,让你轻松掌握这一技术,为你的运维工作带来革命性的变化。
自动化运维的利器:Ansible在配置管理中的应用
【10月更文挑战第39天】本文旨在通过深入浅出的方式,向读者展示如何利用Ansible这一强大的自动化工具来优化日常的运维工作。我们将从基础概念讲起,逐步深入到实战操作,不仅涵盖Ansible的核心功能,还会分享一些高级技巧和最佳实践。无论你是初学者还是有经验的运维人员,这篇文章都会为你提供有价值的信息,帮助你提升工作效率。
自动化运维之路:使用Ansible进行服务器管理
在现代IT基础设施中,自动化运维已成为提高效率和可靠性的关键。本文将引导您通过使用Ansible这一强大的自动化工具来简化日常的服务器管理任务。我们将一起探索如何配置Ansible、编写Playbook以及执行自动化任务,旨在为读者提供一条清晰的路径,从而步入自动化运维的世界。
104 11
自动化运维:使用Ansible实现批量服务器配置
在快速迭代的IT环境中,高效、可靠的服务器管理变得至关重要。本文将介绍如何使用Ansible这一强大的自动化工具,来简化和加速批量服务器配置过程。我们将从基础开始,逐步深入到更复杂的应用场景,确保即使是新手也能跟上节奏。文章将不包含代码示例,而是通过清晰的步骤和逻辑结构,引导读者理解自动化运维的核心概念及其在实际操作中的应用。
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等