朋友,
我尝试在 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 install 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"
我也检查了我的 /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 解释器。知道如何解决这个问题吗?我有很多信息,但我有点不知道如何解释它以找到解决方案?
答案 0 :(得分:2)
解决 ansible 中缺少 python 依赖项的一个常见解决方案是将需求包含在剧本中,以确保它不仅当前可用,而且将来也可用< /p>
- 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: ...