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`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
144 25
|
1月前
|
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’:问题解决方案-优雅草卓伊凡
68 13
yum install -y net-snmp-devel 安装不成功 zabbix项目安装,Errors during downloading metadata for repository ‘extras-common’:问题解决方案-优雅草卓伊凡
【Linux】另一种基于rpm安装yum的方式
通过本文的方法,您可以在离线环境中使用RPM包安装YUM并进行必要的配置。这种方法适用于无法直接访问互联网的服务器或需要严格控制软件源的环境。通过配置本地YUM仓库,确保了软件包的安装和更新可以顺利进行。希望本文能够为您在特定环境中部署YUM提供实用的指导。
447 0
Linux 安装 mysql【使用yum源进行安装】
这篇文章介绍了在Linux系统中使用yum源安装MySQL数据库的步骤,包括配置yum源、安装MySQL服务、启动服务以及修改root用户的默认密码。
Linux 安装 mysql【使用yum源进行安装】
Linux 使用Yum安装Go和配置环境
Linux 使用Yum安装Go和配置环境
|
9月前
yum 可以安装rpm包
【6月更文挑战第18天】yum 可以安装rpm包
833 0
在CentOS上使用yum安装与使用MySQL
在CentOS操作系统上使用yum包管理器安装和配置MySQL数据库的详细步骤,包括下载MySQL的yum源配置、安装MySQL服务、启动和停止服务、设置开机自启动、获取临时密码、修改root用户密码、授权用户以及处理相关问题。同时,文章还包含了一些操作的截图,帮助用户更直观地理解安装和配置过程。
2118 0
在CentOS上使用yum安装与使用MySQL
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
347 11
CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org;"之解决办法(换源)
CentOS7 yum安装报错“Could not resolve host: mirrorlist.centos.org; Name or service not known“之解决办法(换源)