Ansible is not equipped with ssh connection, user password login

Ansible does not match the ssh password-free link, and directly use the ssh user password to connect, you must install sshpass first.

sshpass download address: http://sourceforge.net/projects/sshpass/

Run the following commands to install:

tar -zxvf sshpass-1.05.tar.gz
cd sshpass-1.05                
./configure             
make && make install

After the installation is complete, enter sshpass and the following prompt appears, the installation is successful:

# sshpass
Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
   -f filename   Take password to use from file
   -d number     Use number as file descriptor for getting password
   -p password   Provide password as argument (security unwise)
   -e            Password is passed as env-var "SSHPASS"
   With no parameters - password will be taken from stdin
   -h            Show help (this screen)
   -V            Print version information
At most one of -f, -d, -p or -e should be used

Add user password to /etc/ansible/hosts file to authenticate ssh connection

[test]
127.0.0.1 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123456
192.168.1.103 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123456

Error summary:

[root@localhost ~]# ansible test -m ping
127.0.0.1 | FAILED! => {
    "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."
}
192.168.1.103 | FAILED! => {
    "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."
}

When ssh connects for the first time, it will generally prompt to enter yes to confirm that the key string is added to the ~/.ssh/known_hosts file. And there is a fingerprint key string in the ~/.ssh/known_hosts file of this machine

Workaround: Change the following parameters in the ansible.cfg file:

#host_key_checking = False just remove the #

Reference URL:

https://www.cnblogs.com/iois/p/6230800.html

https://www.cnblogs.com/ylqh/p/5902259.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324935221&siteId=291194637