Ansible的安装

1.先决条件

  • 确保存在OpenSSH;
  • 确保Python的版本;
  • 管理节点需要安装Ansible,被管理节点不需要安装Ansible。

在这里插入图片描述
2.安装方式

  • yum方式
[root@master~]# yum install epel-release -y
[root@master~]# yum install ansible -y
  • pip方式
[root@master~]# yum install epel-release -y
[root@master~]# yum install python2-pip
[root@master~]# pip install ansible

3.查看版本

[root@master ~]# ansible --version
ansible 2.9.27
  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, Oct 14 2020, 14:45:30) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]      #使用的python版本

4.管理节点和被管理节点建立ssh信任关系

  • 管理节点(ansible)创建密钥对
[root@master ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):     #回车
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:KTRAZIYdlC9P9i3jjx0vD0FvBa7TMGSCuqxdYbD0uyQ root@master
The key's randomart image is:
+---[RSA 2048]----+
|   *Oo .. o .    |
|  .o=..  + . .   |
|   . *o   + . .  |
|    +.B. o * .   |
|   . B.+S.+ +    |
|    E =.+ .+     |
|   o + o oo      |
|  . . . .o.+     |
|        ..ooo    |
+----[SHA256]-----+
  • 将本地公钥传输被管理节点
    1. 如果只有一个被管理节点:
[root@master ~]# ssh-copy-id root@10.0.128.171    #被管理节点IP地址
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '10.0.128.171 (10.0.128.171)' can't be established.
ECDSA key fingerprint is SHA256:T+SOOfRX7ES7g0Qv3xdCyuiODADig0aK/AU74iGuY9M.
ECDSA key fingerprint is MD5:5a:47:ee:c5:6c:78:68:b7:bc:22:76:d1:4f:ef:f8:19.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@10.0.128.171's password:     #被管理节点主机密码

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@10.0.128.171'"
and check to make sure that only the key(s) you wanted were added.

5.测试

[root@master ~]# ssh root@10.0.128.171
Last login: Sun Apr 23 10:47:03 2023 from 10.0.255.2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孤岛与风

谢谢您的认可~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值