Ansible错误汇总

最近使用Ansible批量添加zabbix-agent时,碰到不少问题,在此记录一下。

Ansible版本:2.9.2
Python版本:2.7.5
pywinrm版本:0.4.3

当使用Ansible管理主机时报错
-- 首先要排除网络问题
-- 其次根据错误提示来判断问题根源(可以在命令后添加-vvvvvv来查看详细信息)

CentOS环境

报错:Shared connection to xxx.xxx.xxx.xxx closed

xxx.xxx.xxx.xxx | FAILED! => {
    "changed": false, 
    "module_stderr": "Shared connection to xxx.xxx.xxx.xxx closed.\r\n", 
    "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1657010661.53-56592330631735/command.py\", line 123, in <module>\r\n    f.write(z.read('ansible_module_command.py'))\r\n  File \"/data/app/python/Lib/zipfile.py\", line 1314, in read\r\n    with self.open(name, \"r\", pwd) as fp:\r\n  File \"/data/app/python/Lib/zipfile.py\", line 1425, in open\r\n    return ZipExtFile(zef_file, mode, zinfo, zd, True)\r\n  File \"/data/app/python/Lib/zipfile.py\", line 758, in __init__\r\n    self._decompressor = _get_decompressor(self._compress_type)\r\n  File \"/data/app/python/Lib/zipfile.py\", line 678, in _get_decompressor\r\n    return zlib.decompressobj(-15)\r\nAttributeError: 'NoneType' object has no attribute 'decompressobj'\r\n", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}

module_stdout:
Traceback (most recent call last):  
File "/root/.ansible/tmp/ansible-tmp-1657786888.03-3276-66518254516251/AnsiballZ_ping.py", line 114, in 
    <module> _ansiballz_main()  
File "/root/.ansible/tmp/ansible-tmp-1657786888.03-3276-66518254516251/AnsiballZ_ping.py", line 106, in             
    _ansiballz_main invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)  
File "/root/.ansible/tmp/ansible-tmp-1657786888.03-3276-66518254516251/AnsiballZ_ping.py", line 41, in invoke_module    
    f.write(z.read('__main__.py'))  
File "/data/app/python/Lib/zipfile.py", line 1314, in read    
    with self.open(name, "r", pwd) as fp:  
File "/data/app/python/Lib/zipfile.py", line 1425, in open    
    return ZipExtFile(zef_file, mode, zinfo, zd, True)  
File "/data/app/python/Lib/zipfile.py", line 758, in __init__    
    self._decompressor = _get_decompressor(self._compress_type)  
File "/data/app/python/Lib/zipfile.py", line 678, in _get_decompressor    
    return zlib.decompressobj(-15)AttributeError: 'NoneType' object has no attribute 'decompressobj'",

原因:
  查看目标主机,发现是升级过python版本(python2.7.5 -> python3.6.5),在编译安装时没有安装zlib-devel库。

解决方式:
  需要安装zlib-devel库,并重新编译安装python3.6.5。

报错:connect to host xxx.xxx.xxx.xxx port 22: Connection timed out

xxx.xxx.xxx.xxx | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host xxx.xxx.xxx.xxx port 22: Connection timed out\r\n",
"unreachable": true
}

原因:
  导致出现Connection timed out的基本都是网络性问题。

解决方式:
  排查网络连通性以及端口是否开启,目标主机有没有开启防火墙。

报错:Authentication failure

# Ansible 2.4.0
xxx.xxx.xxx.xxx | UNREACHABLE! => {
    "changed": false, 
    "msg": "Authentication failure.", 
    "unreachable": true
}

# Ansible 2.9.2
xxx.xxx.xxx.xxx | UNREACHABLE! => {
    "changed": false,
    "msg": "Invalid/incorrect password: Permission denied, please try again.",
    "unreachable": true
}

原因:
  密码错误

解决方法
  更改正确密码

报错:安装时报错缺少libpcre.so.1()库

fatal: [xxx.xxx.xxx.xxx]: FAILED! => {
"changed": true, 
"cmd": ["rpm", "-ivh", "/etc/zabbix/zabbix-agent-4.0.9-3.el7.x86_64.rpm"], 
"delta": "0:00:00.086235", "end": "2022-07-15 05:38:46.825589", 
"msg": "non-zero return code", 
"rc": 1, "start": "2022-07-15 05:38:46.739354", 
"stderr": "warning: /etc/zabbix/zabbix-agent-4.0.9-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY\nerror: Failed dependencies: libpcre.so.1()(64bit) is needed by zabbix-agent-4.0.9-3.el7.x86_64 systemd is needed by zabbix-agent-4.0.9-3.el7.x86_64", 
"stderr_lines": [
    "warning: /etc/zabbix/zabbix-agent-4.0.9-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY", 
    "error: Failed dependencies:", 
    "libpcre.so.1()(64bit) is needed by zabbix-agent-4.0.9-3.el7.x86_64",
    "systemd is needed by zabbix-agent-4.0.9-3.el7.x86_64"
    ], 
"stdout": "", 
"stdout_lines": []
}

原因:
  1、报错缺少libpcre.so.1()时,首先检查zabbix-agent版本是否与目标主机的内核版本一致;
  2、如内核版本与agent一致,则再查看目标主机中是否缺少libpcre.so.1库

解决方法:
  更换与目标主机内核版本一致的agent版本

报错: Permission denied (publickey)

xxx.xxx.xxx.xxx | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: root@xxx.xxx.xxx.xxx: Permission denied (publickey).",
    "unreachable": true
}

原因:
  目标主机使用秘钥登录

解决方法:
  1、将Ansible主机的ssh公钥拷贝到目标主机(推荐);
  2、修改目标主机的ssh登录方式;

报错:No space left on device

xxx.xxx.xxx.xxx | UNREACHABLE! => {
    "changed": false,
    "msg": "mkdir: cannot create directory ‘/root/.ansible’: No space left on device\n",
    "unreachable": true
}

原因:
  目标主机的磁盘空间不足

解决方法:
  清理磁盘空间

Windows环境

报错:the specified credentials were rejected by the server

xxx.xxx.xxx.xxx | UNREACHABLE! => {
    "changed": false,
    "msg": "ntlm: the specified credentials were rejected by the server",
    "unreachable": true
}

原因:
  目标主机密码不正确

解决方法:
  修改正确密码

报错:Failed to establish a new connection [Errno 111]

xxx.xxx.xxx.xxx10.2.50.73 | UNREACHABLE! => {
    "changed": false,
    "msg": "ntlm: HTTPConnectionPool(host='xxx.xxx.xxx.xxx', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ff2040e7f50>: Failed to establish a new connection: [Errno 111] Connection refused',))",
    "unreachable": true
}

原因:
  1、查看网络是否互通;
  2、查看目标主机没有开放5985远程端口。

解决方法:
  查看目标主机winrm远程服务是否开启 - powershell -> (Get-Service -Name winrm).status
    -- 如果没有运行,运行1.ps1脚本开启winrm远程服务(需注意 - Powershell>=3.0, .NET>=4.0)

报错:Failed to establish a new connection: [Errno 113]

xxx.xxx.xxx.xxx | UNREACHABLE! => {
    "changed": false,
    "msg": "ntlm: HTTPConnectionPool(host='xxx.xxx.xxx.xxx', port=5985): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f06d333e650>: Failed to establish a new connection: [Errno 113] No route to host',))",
    "unreachable": true
}

原因:
  1、这台主机是Linux系统,但是使用windows方式连接;
  2、这台主机防火墙开启,No route to host报错是因为防火墙没有开放端口;

解决方法:
  在防火墙上开启对应端口

报错:Connection to xxx.xxx.xxx.xxx timed out

xxx.xxx.xxx.xxx | UNREACHABLE! => {
    "changed": false,
    "msg": "ntlm: HTTPConnectionPool(host='xxx.xxx.xxx.xxx', port=5985): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7ff2040cff90>, 'Connection to xxx.xxx.xxx.xxx timed out. (connect timeout=30)'))",
    "unreachable": true
}

原因:
  1、网络不通;
  2、端口超时

解决方法:
  1、开通网络互通策略;
  2、查看目标主机是否开放5985端口(winrm服务);

报错:winrm send_input failed

# Ansible 2.4.0
xxx.xxx.xxx.xxx | FAILED! => {
"changed": false,
    "module_stderr": "An error occurred while creating the pipeline.\r\n    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException\r\n    + FullyQualifiedErrorId : RuntimeException\r\n \r\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 3221226519
}

# Ansible 2.9.2
[WARNING]: ERROR DURING WINRM SEND INPUT - attempting to recover: WinRMError WinRMError(u"\u7ba1\u9053\u5df2\u7ed3\u675f\u3002  (extended fault data:
{u'fault_subcode': 'w:InternalError', u'fault_code': 's:Receiver', u'wsmanfault_code': '109', 'transport_message': u'Bad HTTP response returned from server.
Code 500', 'http_status_code': 500})",)

xxx.xxx.xxx.xxx | FAILED! => {
    "msg": "winrm send_input failed; \nstdout: \nstderr "
}

原因:
  这个原因没有找到,如果有找到原因和解决方法的小伙伴,希望能分享一下,不胜感激。

解决方法:

报错:There is not enough space on the disk

An exception occurred during task execution. To see the full traceback, use -vvv. The error was:    at System.Management.Automation.CommandProcessorBase.Complete()
xxx.xxx.xxx.xxx | FAILED! => {
    "changed": false,
    "msg": "internal error: failed to run exec_wrapper action module_powershell_wrapper: Exception calling \"CompileAssemblyFromDom\" with \"2\" argument(s): \"There is not enough space on the disk.\r\n\""
}

原因:
  目标主机磁盘不足

解决方法:
  清理磁盘空间

报错:The RPC server is unavailable

xxx.xxx.xxx.xxx | UNREACHABLE! => {
    "changed": false,
    "msg": "ntlm: The RPC server is unavailable.  (extended fault data: {u'fault_subcode': 'w:InternalError', u'fault_code': 's:Receiver', u'wsmanfault_code': '2147944122', 'transport_message': u'Bad HTTP response returned from server. Code 500', 'http_status_code': 500})",
    "unreachable": true
}

原因:
  目标主机的RPC服务未开启

解决方法:
  开启RPC服务
    -- win+R -> 输入services.msc -> 在服务中找到RPC Exdpoint Mapper -> 右键选择属性 -> 启动类型:自动,服务状态选择启动;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,639评论 6 513
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,093评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 167,079评论 0 357
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,329评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,343评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,047评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,645评论 3 421
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,565评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,095评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,201评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,338评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,014评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,701评论 3 332
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,194评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,320评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,685评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,345评论 2 358

推荐阅读更多精彩内容