Ansible找不到pexpect,但它已安装

2024-09-28 22:40:14 发布

您现在位置:Python中文网/ 问答频道 /正文

朋友们

我试图在CentOS 8主机上使用ansible.builtin.expect模块执行任务,出现以下错误:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError:
No module named 'pexpect'fatal: [gblix]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library 
(pexpect) on centos's Python /usr/libexec/platform-python. Please read the module documentation and install it in the 
appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter,
please consult the documentation on ansible_python_interpreter"}

我运行了pip3安装pexexpect,它已安装:

Requirement already satisfied: pexpect in /home/marcelo/.local/lib/python3.6/site-packages
Requirement already satisfied: ptyprogress>=0.5 in /home/marcelo/.local/lib/python3.6/site-packages
(from pexpect)

然后我运行ansible gblix -m setup | grep ansible_python_version,结果是"ansible_python_version": "3.6.8"

我还检查了my/usr/bin目录,输出如下所示:

[marcelo@centos bin]$ ls -l | grep python
lrwxrwxrwx. 1 root root       9 Aug 31  2020 python2 -> python2.7
-rwxr-xr-x. 1 root root    8224 Aug 31  2020 python2.7
lrwxrwxrwx. 1 root root      25 May 16 14:52 python3 -> /etc/alternatives/python3
lrwxrwxrwx. 1 root root      31 Nov  4  2020 python3.6 -> /usr/libexec/platform-python3.6
lrwxrwxrwx. 1 root root      32 Nov  4  2020 python3.6m -> /usr/libexec/platform-python3.6m
lrwxrwxrwx. 1 root root      24 Feb 23 19:27 unversioned-python -> /etc/alternatives/python

如果我没有错的话,pexpect已经安装,并且ansible正在使用正确的python解释器。你知道我该怎么解决这个问题吗?我有很多信息,但我不知道如何解释来找到解决方案


Tags: theinonusrlibraryrequiredrootansible
1条回答
网友
1楼 · 发布于 2024-09-28 22:40:14

ansible中缺少python依赖项的一个常见解决方案是只在剧本中包含需求,以确保它不仅当前可用,而且将来也可用

- name: ensure pexpect is installed in the playbook python
  pip:
    name: pexpect
    state: present

- name: now you can use that dependency in all cases
  expect: ...

相关问题 更多 >