目录
管理端: 192.168.100.21
被管理端:192.168.100.22
被管理端:192.168.100.23
管理端操作
安装epel源
[root@master ~]# yum -y install epel-release
[root@master ~]# yum -y install ansible ##安装ansible
查看ansible版本
[root@master ~]# ansible --version 查看版本
[root@master ~]# yum -y install tree
[root@master ~]# tree /etc/ansible/ //树状结构展示文件夹
/etc/ansible/
├── ansible.cfg //ansible配置文件
├── hosts //ansible的主仓库,用于存储需要管理的远程主机的相关
└── rolesyu //角色
配置主机清单
[root@master ~]# cd /etc/ansible
[root@master ~]# vi hosts
[webserver]
192.168.100.22
[mysql]
192.168.100.23
生成密钥
[root@master ansible]# 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:4noecl52nXidvmBMZqNRe/mG0R8KqCNIuxlR7iMpXg0 root@master
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| . . |
| o .. . o |
| E .. S...* +..|
| . O. .. X.=.=o|
| . B.=+oo + B.+ +|
|. o ==++.. o o . |
| . o.oo o. |
+----[SHA256]-----+
查看密钥
[root@shuai ~]# ls .ssh/
id_rsa:私钥 id_rsa.pub :公钥
分发密钥到被管理端
[root@master ~]# ssh-copy-id root@192.168.100.22
[root@master ~]# ssh-copy-id root@192.168.100.23
被管理端查看
[root@node2 ~