简体   繁体   English

python3的Ansible模块问题

[英]Ansible module issue with python3

Good afternoon, I have a pymongo module that I installed via pip3 and now I am trying to use it下午好,我有一个通过 pip3 安装的 pymongo 模块,现在我正在尝试使用它

- name: Create role for pbm
  community.mongodb.mongodb_shell:
    login_host: 10.0.44.40
    eval: 'db.getSiblingDB ("admin"). createRole ({"role": "pbmAnyAction", "privileges": [{"resource": {"anyResource": true}, "actions": ["anyAction"] }], "roles": []}); '
  vars:
    ansible_python_interpreter: / usr / bin / python3
  ignore_errors: yes
  when: groups.mongodb.index (inventory_hostname) == 0

and everything works well on my local vagrant vm, but when I run it on the production vm, an error appears并且在我的本地 vagrant vm 上一切正常,但是当我在生产 vm 上运行它时,出现错误

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named pymongo.errors
fatal: [mongodb-01]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (pymongo) on superproduction-mongo-01's Python / usr / bin / python. 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 "}

OS versions for vagrant and production are the same (centos 7) vagrant 和 production 的操作系统版本相同(centos 7)

python3 version output and import pymongo.errors from production vm python3 版本输出并从生产虚拟机导入 pymongo.errors

 python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo.errors
>>> 

from vagrant vm来自流浪虚拟机

python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo.errors
>>>

as you can see output the same如您所见,输出相同

即使我什么都没做也能工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM