ansible 由于不同主机 python 版本不同执行报错

张开发
2026/4/10 23:51:06 15 分钟阅读

分享文章

ansible 由于不同主机 python 版本不同执行报错
报错内容ansible-iinventory/ct all-mpingAn exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module namedansible.module_utils.six.moveskunlun01.ct|FAILED!{changed:false,module_stderr:Shared connection to 10.61.6.1 closed.\r\n,module_stdout:Traceback (most recent call last):\r\nFile\/home/rhlog/.ansible/tmp/ansible-tmp-1775817189.0660183-248546-200217143631416/AnsiballZ_ping.py\, line 102, in module\r\n_ansiballz_main()\r\nFile\/home/rhlog/.ansible/tmp/ansible-tmp-1775817189.0660183-248546-200217143631416/AnsiballZ_ping.py\, line 94, in _ansiballz_main\r\ninvoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\nFile\/home/rhlog/.ansible/tmp/ansible-tmp-1775817189.0660183-248546-200217143631416/AnsiballZ_ping.py\, line 37, in invoke_module\r\nfrom ansible.module_utils import basic\r\nFile\/tmp/ansible_ping_payload_vcew6owj/ansible_ping_payload.zip/ansible/module_utils/basic.py\, line 176, in module\r\nModuleNotFoundError: No module named ansible.module_utils.six.moves\r\n,msg:MODULE FAILURE\nSee stdout/stderr for the exact error,rc:1}python 版本控制端python--versionPython3.10.12被控制端python--versionPython3.12.3解决在控制端执行 ansible 代码的那一端机器上执行。1.安装 venvsudoaptupdatesudoaptinstall-ypython3-venv python3-full2.创建虚拟环境⚠️说明用哪个用户执行 ansible 就用哪个用户创建虚拟环境。python3-mvenv ~/ansible-venvsource~/ansible-venv/bin/activate3.升级 pip(ansible-venv)~$ pipinstall-Upip setuptools wheel4.安装稳定版 Ansible⚠️说明推荐用 core不要用 full ansible bundle。(ansible-venv)~$ pipinstallansible-core2.16.6⚠️警告不要安装 ansible。验证(ansible-venv)~$ ansible--version(ansible-venv)~$ python-cfrom ansible.module_utils import basic(ansible-venv)~$whichpython /home/rhlog/ansible-venv/bin/python(ansible-venv)~$whichansible /home/rhlog/ansible-venv/bin/ansible(ansible-venv)~$ python--versionPython3.10.12(ansible-venv)~$ ansible--versionansible[core2.16.6]configfileNone configured module search path[/home/rhlog/.ansible/plugins/modules,/usr/share/ansible/plugins/modules]ansible python module location/home/rhlog/ansible-venv/lib/python3.10/site-packages/ansible ansible collection location/home/rhlog/.ansible/collections:/usr/share/ansible/collections executable location/home/rhlog/ansible-venv/bin/ansible python version3.10.12(main, Mar32026,11:56:32)[GCC11.4.0](/home/rhlog/ansible-venv/bin/python3)jinja version3.1.6 libyamlTrue

更多文章