Ansible 找不到 pexpect 但已安装
Ansible can not find pexpect but it is installed
朋友,
我试图在 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 解释器。知道如何解决这个问题吗?我有很多信息,但我有点不知道如何解释它以找到解决方案?
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: ...
朋友,
我试图在 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 解释器。知道如何解决这个问题吗?我有很多信息,但我有点不知道如何解释它以找到解决方案?
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: ...