ping報(bào)錯(cuò)
$? ansible all -m ping
192.168.1.14 | UNREACHABLE! => {
? ? "changed": false,
? ? "msg": "Failed to connect to the host via ssh: test1,ansible_ssh_pass=test1@192.168.1.14: Permission denied (publickey,password).",
? ? "unreachable": true
}
##
2022-04-26
問(wèn)題搞定了。
做這一步的時(shí)候注意配置受控主機(jī)的用戶。
2.添加本機(jī)的public SSH key到目標(biāo)機(jī)器(受控機(jī)器)的authorized_keys
第一種情況
不配置受控主機(jī)的連接用戶,僅配置受控主機(jī)IP。主控機(jī)器會(huì)使用主控機(jī)器的當(dāng)前用戶連接到受控機(jī)器。如果受控機(jī)器沒(méi)有此用戶則出現(xiàn)報(bào)錯(cuò)。
第二種情況
配置受控主機(jī)的連接用戶。
vim /etc/ansible/hosts
user@192.168.1.10
or
192.168.1.10?ansible_ssh_user="user"
這時(shí)候漏洞出現(xiàn)在ssh-copy-id上,如果ssh-copy-id?未指定用戶,或者指定用戶與上述配置的用戶不一致,也會(huì)導(dǎo)致報(bào)錯(cuò)。
正確配置
1.編輯/etc/ansible/hosts文件,加入內(nèi)容
192.168.1.10?ansible_ssh_user="user"
2.ssh-copy-id指定用戶
ssh-copy-id?user@192.168.1.10