ansible批量自动化配置文件修改
背景:客户100多台的主机修改ssh默认端口,ansible完成批量自动化更改
利用三台测试机演示
1.ansible软件yum安装
Ansible的yum源:
baseurl=https://mirror.tuna.tsinghua.edu.cn/epel/7/x86_64/
[root@node1 ~]# yum -y install ansible
2.ansible环境配置
[root@node1 ansible]# pwd
/etc/ansible
[root@node1 ansible]# cat hosts
[test]
172.20.0.247
172,20.0.249
3.主机免密登录
[root@node1 ansible]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/devop/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/devop/.ssh/id_rsa.
Your public key has been saved in /home/devop/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:+tABTIFKSJCoLiAGrUNz+ceW6ZYacpCIz6CJl/RvP0Y devop@node1
The key's randomart imag