1 安装ansible
yum -y install ansible
2 安装ssh常见公钥私钥
安装sshd client 并配置
yum install openssh-clients*
vim /etc/ssh/sshd_config
RSAAuthentication yes # 启用 RSA 认证
PubkeyAuthentication yes # 启用公钥私钥配对认证方式
AuthorizedKeysFile %h/.ssh/authorized_keys # 公钥文件路径
创建本地存放公钥的文件
# -t 指定类型,-f指定文件生成路径,-P指定文件密码(''表示无密码)
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
#推送公钥 两个命令都可以用 第一个不需要输入密码 :
sshpass -pbyzoro.com123 ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
#这个命令会提示输入次ip的ssh登录密码 推荐使用:
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
3 配置ansible
vim /etc/ansible/hosts
[A8]
192.66.1.205
192.66.1.207
..
[OA]
192.66.1.200
[all_agent:children]
A8
OA
4测试单个组组和children命令
ansible all_agent -m ping
ansible A8 -m yum -a "name=tree state=installed"
ansible all_agent -m yum -a "name=tree state=installed"
ansible all_agent -m shell -a “sed -i 'N;96aServer=192.168.1.96' ”
ansible all_agent -m shell -a “systemctl restart zabbix-agent ”
ansible all_agent -m shell -a “systemctl enable zabbix-agent ”
公钥私钥有问题的童鞋请阅读 : https://blog.csdn.net/JLongSL/article/details/78157112