[英]Ansible fails with ModuleNotFoundError: No module named 'pexpect'
I have three hosts, all running Ubuntu 18.04 with latest updates:我有三台主机,都运行带有最新更新的 Ubuntu 18.04:
ansible --version
yields: ansible --version
产生:
ansible 2.9.6
config file = /home/marco/Desktop/playbook/ansible.cfg
configured module search path = [u'/home/marco/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.17 (default, Nov 7 2019, 10:07:09) [GCC 7.4.0]
ansible.cfg
contains the line interpreter_python = auto
. ansible.cfg
包含行interpreter_python = auto
。
My playbook works fine when run with target host staging.使用目标主机暂存运行时,我的剧本运行良好。 But when running with target host prod, it fails when running the expect module:但是当使用目标主机 prod 运行时,它在运行expect模块时失败:
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'pexpect'
fatal: [prod]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (pexpect) on prod's Python /usr/bin/python3. Please read module documentation and install 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"}
I have tried to solve the problem by installing libries on master by我试图通过在 master 上安装库来解决这个问题
apt-get install python-pexpect
apt-get install python-pip
pip install pexpect
and on prod by adding并通过添加
- name: Install packages
apt:
name:
- python-pexpect
- python-pip
- name: Install Python modules
command: pip install pexpect
to the playbook, but it did not help.到剧本,但它没有帮助。
Try the built-in pip
Anisble module, it will detect which version of pip Ansible is using on the controlled node.试试内置的pip
Anisble 模块,它会检测在受控节点上使用的是哪个版本的 pip Ansible。
- name: Install pip
apt:
update_cache: yes
name:
- python3-pip
- name: Install pexpect
pip:
name: pexpect
You can install geerlingguy.pip role from ansible galaxy with the following command :您可以使用以下命令从ansible Galaxy安装geerlingguy.pip角色:
ansible-galaxy install geerlingguy.pip
then add this on top of your playbook :然后将其添加到您的剧本之上:
hosts: "{{myhost}}"
vars:
pip_install_packages:
- name: pexpect
pip_package: python-pip
pip_executable: pip
roles:
- geerlingguy.pip
You can then use expect in ansible normally.然后您可以正常使用 ansible 中的 expect 。
this is how i solved it这就是我解决它的方法
- name: Install pexpect
pip:
name: pexpect
become: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.