我有三台主机,全部运行带有最新更新的 Ubuntu 18.04:
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]
Run Code Online (Sandbox Code Playgroud)
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"}
Run Code Online (Sandbox Code Playgroud)
我尝试通过在 master 上安装库来解决问题
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]
Run Code Online (Sandbox Code Playgroud)
并在产品上添加
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"}
Run Code Online (Sandbox Code Playgroud)
到剧本,但它没有帮助。
尝试内置的pipAnisble 模块,它将检测受控节点上使用的 pip Ansible 版本。
- name: Install pip
apt:
update_cache: yes
name:
- python3-pip
- name: Install pexpect
pip:
name: pexpect
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13039 次 |
| 最近记录: |