sudo apt update
sudo apt install ansible
sudo vim /etc/ansible/hosts
[ceshi3]
192.168.1.181 ansible_ssh_user='cla' ansible_ssh_pass='cla' ansible_ssh_port=22
192.168.1.182 ansible_ssh_user='cla' ansible_ssh_pass='cla' ansible_ssh_port=22
192.168.1.183 ansible_ssh_user='cla' ansible_ssh_pass='cla' ansible_ssh_port=22
测试:
cla@cla:~$ ansible ceshi3 -a 'date'
192.168.1.183 | SUCCESS | rc=0 >>
Wed Sep 25 18:19:45 CST 2019
192.168.1.182 | SUCCESS | rc=0 >>
Wed Sep 25 18:19:45 CST 2019
192.168.1.181 | SUCCESS | rc=0 >>
Wed Sep 25 18:19:45 CST 2019
可能会出现一下错误
192.168.1.181 | FAILED | rc=0 >>
ERROR! 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.
# 如果出现以上错误,要先用ssh登录一下
cla@cla:~$ ssh cla@192.168.1.181
The authenticity of host '192.168.1.181 (192.168.1.181)' can't be established.
ECDSA key fingerprint is SHA256:XP/3w0dm+2cg0qxSCDjQtjJo5Zg/020+s5H45yo7IDo.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.181' (ECDSA) to the list of known hosts.
cla@192.168.1.181's password: