ansible(3)-host list, ssh, public key and private key

In the /etc/ansible/hosts file, we can add a list of hosts:
Insert picture description here
At this time, we can execute commands through these ip and groups:
Insert picture description here
the error is guaranteed because the content of the ssh key (local password) must be added:
Insert picture description here
access the first The host group can also succeed:
Insert picture description here
visit the second host group again: the
Insert picture description here
error is reported here because we did not add the records of the two hosts to /root/.ssh/known_hosts: at
Insert picture description here
Insert picture description here
Insert picture description here
this time, observe the file and find that it has been added.
Re-implement to succeed
Insert picture description here

No password

If you do not want to enter the -k parameter, you can add the parameter in /etc/ansible/hosts:
Insert picture description here
or:Insert picture description here

So there is no need to enter the -k parameter to access.
Insert picture description here
You can also generate a key pair:
Insert picture description here
send the key (public key) pair to the corresponding host, so there is no need to enter -k to enter the password:
Insert picture description here
similarly, add two more hosts:
Insert picture description here
Insert picture description here
there are also on these two hosts Authentication key, so we can visit without secret:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_48445640/article/details/109446560