目录
1、配置三个主机 /etc/hosts 文件,实现通过域名访问
2、配置三个源(本地源、epel源、Centos-stream)
4、通过 ansible --version 判断是否安装成功
四、ansible使用ssh连接受管主机,一般不建议用管理用户,要求通过普通用户 redhat 进行链接
1、将公钥发送给server主机和node1主机的redhat用户
一、环境配置
角色
|
主机名
|
ip
地址
|
组名 |
控制主机 |
xixi.example.com
|
192.168.225.130 | xixi |
受控主机
/
被管节点
|
server.example.com
|
192.168.225.140 | server |
受控主机
/
被管节点
|
node1.example.com
|
192.168.225.150 | node1 |
1、配置三个主机 /etc/hosts 文件,实现通过域名访问
[root@server ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.225.130 xixi.example.com xixi
192.168.225.140 server.example.com server
192.168.225.150 node1.example.com node1
2、配置SSH远程免密连接
2.1 在控制主机生成密钥
[root@xixi ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:sHuk59eqgGlv45SwA5BBcE1nfIGux9jRrxGvA3ynWOs root@xixi
The key's randomart image is:
+---[RSA 3072]----+
|=..o..o... |
| + .oo . |
|o ..o |
| . ooo |
| . .*..S+ |
| .o=*=+ + |
| *.*=oB . |
| . ++=* . . |
| oooE+.. |
+----[SHA256]-----+
2.2 发送公钥到受控主机
[root@xixi ~]# ssh-copy-id -i server
[root@xixi ~]# ssh-copy-id -i node1
二、受控主机(xixi)安装ansible
1、确认主机能够上网
2、配置三个源(本地源、epel源、Centos-stream)
2.1 配置本地源
- 查看/etc/yum.repos.d目录下之前是否有配置文件