公司內部補容許用key來認證,並且是內網沒法訪問外網,只能經過源碼安裝和裝特定模塊達到密碼登錄的功能ssh
1.安裝sshpasside
運行下列命令安裝:this
tar -zxvf sshpass-1.05.tar.gz cd sshpass-1.05 ./configure make && make install.net
安裝完成後輸入sshpass出現以下提示即安裝成功orm
#sshpassip
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字符串
/etc/ansible/hosts文件中添加用戶密碼,認證ssh鏈接get
[test] 127.0.0.1 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123456 192.168.1.137 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=123456源碼
2.錯誤彙總:it
[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." }
3.緣由和解決辦法:
ssh第一次鏈接的時候通常會提示輸入yes 進行確認爲將key字符串加入到 ~/.ssh/known_hosts 文件中。而本機的~/.ssh/known_hosts文件中並有fingerprint key串
解決方法:在ansible.cfg文件中更改下面的參數:
#host_key_checking = False 將#號去掉便可