In the /etc/ansible/hosts file, we can add a list of hosts:
At this time, we can execute commands through these ip and groups:
the error is guaranteed because the content of the ssh key (local password) must be added:
access the first The host group can also succeed:
visit the second host group again: the
error is reported here because we did not add the records of the two hosts to /root/.ssh/known_hosts: at
this time, observe the file and find that it has been added.
Re-implement to succeed
No password
If you do not want to enter the -k parameter, you can add the parameter in /etc/ansible/hosts:
or:
So there is no need to enter the -k parameter to access.
You can also generate a key pair:
send the key (public key) pair to the corresponding host, so there is no need to enter -k to enter the password:
similarly, add two more hosts:
there are also on these two hosts Authentication key, so we can visit without secret: