本文档记录ansible使用中遇到的错误及解决办法
问题一:
[root@host-10-1-241-158 logs]# ssh 10.1.241.161
ssh_exchange_identification: read: Connection reset by peer
ips10.1.241.159 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh_exchange_identification: read: Connection reset by peer\r\n",
"unreachable": true
}
[root@host-10-1-241-158 logs]# ansible root10.1.241.161 -m shell -a 'pwd'
root10.1.241.161 | FAILED | rc=0 >>
MODULE FAILURE
[root@host-10-1-241-158 logs]# ansible ips10.1.241.161 -m shell -a 'pwd'
ips10.1.241.161 | UNREACHABLE! => {
"changed": false,
"msg": "Authentication failure.",
"unreachable": true
}
10.1.241.161主机上
vi /etc/hosts.deny
有sshd,sftp,telnet,ftp: 10.1.241.158
如何解除/etc/hosts.deny
161上执行:
[root@host-10-1-241-161 ~]# service denyhosts stop
sent DenyHosts SIGTERM
vi /etc/hosts.deny中,删除对应的主机信息
Authentication failure."报错是因为:/etc/ansible/hosts的用户,在被连接主机上没有sudo权限:
vi /etc/sudoers
添加对应权限即可。
ips10.1.241.159 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh_exchange_identification: read: Connection reset by peer\r\n",
"unreachable": true
}
解决方法:
service denyhosts stop
cat /dev/null >/etc/hosts.deny
问题二:
+ ansible IPSMachines -m shell -a 'pwd'
root10.1.235.28 | UNREACHABLE! => {
"changed": false,
"msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo $HOME/.ansible/tmp/ansible-tmp-1536806706.35-106960540689166 `\" && echo ansible-tmp-1536806706.35-106960540689166=\"` echo $HOME/.ansible/tmp/ansible-tmp-1536806706.35-106960540689166 `\" ), exited with result 1",
"unreachable": true
}
root10.1.235.27 | UNREACHABLE! => {
"changed": false,
"msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo $HOME/.ansible/tmp/ansible-tmp-1536806706.35-1073010745840 `\" && echo ansible-tmp-1536806706.35-1073010745840=\"` echo $HOME/.ansible/tmp/ansible-tmp-1536806706.35-1073010745840 `\" ), exited with result 1",
"unreachable": true
}
【定位】原因是,被登录主机上的ansible用户的密码不对了;或者密码过期了;修改下对应用户的密码为正确密码即可;