gpt4 book ai didi

python - Ansible 失败并出现 ModuleNotFoundError : No module named 'pexpect'

转载 作者:行者123 更新时间:2023-12-05 00:46:23 25 4
gpt4 key购买 nike

我有三台主机,都运行最新更新的 Ubuntu 18.04:

  • master 和 staging 是我自己从 Ubuntu 18.04 镜像安装的主机。
  • prod 是我从提供商处租用的主机,因此除了选择 Ubuntu 18.04 之外,我无法控制基本安装。
  • master 已安装 Ansible。

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 包含 interpreter_python = auto 行。

我的剧本在使用目标主机登台运行时运行良好。但是当使用目标主机 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"}

我试图通过在 master 上安装库来解决问题

apt-get install python-pexpect
apt-get install python-pip
pip install pexpect

然后添加

- name: Install packages
apt:
name:
- python-pexpect
- python-pip
- name: Install Python modules
command: pip install pexpect

到剧本,但没有帮助。

最佳答案

试试内置的 pip Ansble 模块,它会检测被控节点上使用的是哪个版本的 pip Ansible。

    - name: Install pip
apt:
update_cache: yes
name:
- python3-pip

- name: Install pexpect
pip:
name: pexpect

关于python - Ansible 失败并出现 ModuleNotFoundError : No module named 'pexpect' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60893183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com