ansible 实现批量免密:
1)首先在ansible的master主控机上生成公私秘钥
执行命令:ssh-keygen -t rsa
2)配置好ansible的hosts,默认路径在/etc/ansible
[check]
10.126.6.[10:17]
10.126.7.11
3)执行以下ansible命令:
ansible check -m authorized_key -a "user=zdkx exclusive=true manage_dir=true key='$(< /root/.ssh/id_rsa.pub)'" -k
(注意:user=zdkx是slave(allweb)主机组的用户;/root/.ssh/id_rsa.pub是master主机的公钥)
SSH password:(输入密码)
----到此设置完成!
##############
报错:("msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host's fingerprint to your known_hosts file to manage this host)
解决方案:
vi /etc/ansible/ansible.cfg
host_key_checking = False