1:基于sshpass 分布密钥
《1》:yum -y install sshpass 安装sshpass (注:这里不需要安装,因为在安装ansible的时候已经安装了)
《2》:sshpass -p gzf123. ssh-copy-id root@192.168.100.20 分发时不需要密码
他的格式:Ansible 组名 -m 模块 -a 参数
《3》:ansible webserver -m command -a "touch /tmp/11111" (注:command 是支持shell命令的)
《4》:vim /etc/ansible/hosts 编辑文件。(注:删除虚拟机2的密钥对,不需要创建密钥对,也可以)
《5》:写入:(注:客户机名称,对应的地址,用户,密码:写root的密码)
[nokey]
client1 ansible_ssh_host=192.168.100.20 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=gzf123.
《6》:ansible nokey -m ping ping 也是可以的
《7》:sshpass -pgzf123. ssh-copy-id root@192.168.100.10 (注:在删除对方密钥对的后,建议去传输密钥对,但是不传也是可以的)
《8》:ansible webserver -m ping 回到原来的组
《9》:ansible webserver -m ping --limit 192.168.100.20 仅对192.168.100.20生效
《10》:ansible 192.168.100.20 -m ping (注:直接写入IP地址,也就是仅对于192.168.100.20生效)
《11》:ansible 192.168.100.* -m ping (注:只对一个网段生效,*代表任意的)