简体   繁体   English

Ansible 因 ModuleNotFoundError 失败:没有名为“pexpect”的模块

[英]Ansible fails with ModuleNotFoundError: No module named 'pexpect'

I have three hosts, all running Ubuntu 18.04 with latest updates:我有三台主机,都运行带有最新更新的 Ubuntu 18.04:

  • master and staging are hosts that I have installed myself from an Ubuntu 18.04 image. master 和 staging 是我自己从 Ubuntu 18.04 映像安装的主机。
  • prod is a host that I have leased from a provider, so I have no control on the basic installation beyond selecting Ubuntu 18.04. prod 是我从提供商处租用的主机,因此除了选择 Ubuntu 18.04 之外,我无法控制基本安装。
  • master has Ansible installed. master 安装了 Ansible。

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.

相关问题 pyenv 失败:ModuleNotFoundError: No module named '_ctypes' 错误 - pyenv fails with : ModuleNotFoundError: No module named '_ctypes' error 导入错误:没有名为 pexpect 的模块 - ImportError: No module named pexpect ModuleNotFoundError: No module named 'server_types' Ansible 模块开发 - ModuleNotFoundError: No module named 'server_types' Ansible module development Ansible community.general.ssh_config: ModuleNotFoundError: No module named 'storm' - Ansible community.general.ssh_config: ModuleNotFoundError: No module named 'storm' Firebase 导入模块失败并出现 ModuleNotFoundError: No module named 'Crypto' - Firebase import module fails with ModuleNotFoundError: No module named 'Crypto' tensorflow 在 anaconda 控制台中工作,在笔记本中失败:.ModuleNotFoundError: No module named 'tensorflow' - tensorflow works in anaconda console, fails in notebook with:.ModuleNotFoundError: No module named 'tensorflow' get-pip.py 失败并显示“ModuleNotFoundError: No module named 'dataclasses'” - get-pip.py fails with `ModuleNotFoundError: No module named 'dataclasses'` gunicorn 无法启动 flask 服务器:ModuleNotFoundError:没有名为“请求”的模块 - gunicorn fails to launch flask server: ModuleNotFoundError: No module named 'requests' Pyenv无法在Cygwin上安装python:ModuleNotFoundError:没有名为“ _ctypes”的模块 - Pyenv fails to install python on Cygwin: ModuleNotFoundError: No module named '_ctypes' ModuleNotFoundError:没有名为“keras”的模块 - ModuleNotFoundError: No module named 'keras'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM