一
- ansible -i hosts 111 -m shell -a "whoami",执行出现以下报错。
0.0.0.0 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: \nI wrote it myself!\n\nansible@0.0.0.0: Permission denied (publickey,password,keyboard-interactive).", "unreachable": true }
- 原因:hosts配置文件不正确。
- 解决:修改配置最后三行如下:
[all:vars] //all代表全部,如果有别的名称请灵活更改 ansible_user=账号 ansible_ssh_pass=密码 ansible_sudo_pass=‘root密码’ //这里写su切换root,root的密码,如有需要则写 ansible_ssh_port=端口 //登如果要指定端口登陆,则这里添加,无则不写
二
- 初次安装ansible运行可能会出现的错误:如图
0.0.0.0 | FAILED | rc=-1 >> 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.
- 原因:第一次连接主机需要输入yes确认,可以修改ansible.cfg文件来解决这个问题。
- 修改以下配置: host_key_checking = False
- 默认在第71行,去掉注释即可。
三
- 正常执行ansible报如下错误。
0.0.0.0 | FAILED | rc=-1 >> failed to transfer file to /home/ansible/.ansible/tmp/ansible-local-88903hW16i/tmp62jKAj /home/ansible/.ansible/tmp/ansible-tmp-1621569719.26-141234726549106/AnsiballZ_command.py: dd: error writing ‘/home/ansible/.ansible/tmp/ansible-tmp-1621569719.26-141234726549106/AnsiballZ_command.py’: No space left on device 1+0 records in 0+0 records out 0 bytes (0 B) copied, 0.00513831 s, 0.0 kB/s [WARNING]: piped transfer mechanism failed on [0.0.0.0]. Use ANSIBLE_DEBUG=1 to see detailed information 注意报错有以下字样: 即都是磁盘没有空间导致。 【No space left on device\n】
- 原因:很明显是写错误,说明对方服务磁盘没空间了。
- 解决:上去报错的服务器,清理相关磁盘空间即可。
四
1.执行命令报这个错:
ansible -i hosts 111 -b -f 2 -m shell -a "whoami"
0.0.0.0 | FAILED! => { "changed": false, "module_stderr": "Shared connection to 0.0.0.0 closed.\r\n", "module_stdout": "\r\nsudo: pam_authenticate: Module is unknown\r\n", "msg": "MODULE FAILURE", "rc": 1 }
2.原因:-b参数切换root用户没有权限
3.解决:在hosts文件里边添加一条参数:
[all:vars] ansible_ssh_port=22 ansible_ssh_user=ansible ansible_ssh_pass='123123' ansible_sudo_pass='123456' //这行是添加上去的。有个漏洞,root密码明文,不安全
五
1.执行命令报这个错:
ansible -i hosts 123 -m shell -a "whoami"
255.255.255.255 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\n@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @\r\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\nIT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\r\nSomeone could be eavesdropping on you right now (man-in-the-middle attack)!\r\nIt is also possible that a host key has just been changed.\r\nThe fingerprint for the RSA key sent by the remote host is\nSHA256:wdCWlfhJUkSvIlyoLDtdhnrqOgApgVnOxVuEmsYXkg0.\r\nPlease contact your system administrator.\r\nAdd correct host key in /root/.ssh/known_hosts to get rid of this message.\r\nOffending ECDSA key in /root/.ssh/known_hosts:97\r\nPassword authentication is disabled to avoid man-in-the-middle attacks.\r\nKeyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.\r\nAuthorized users only. All activity may be monitored and reported\nWXJD_ludan@192.168.6.50: Permission denied (publickey,password).", "unreachable": true
2.原因:ssh密钥出问题了
3.解决:
vim /root/.ssh/known_hosts
找到255.255.255.255这台主机的密钥,把他删除掉,即可解决问题。