【问题标题】:Ansible and Opennebula: This module requires pyone to workAnsible 和 Opennebula:这个模块需要 pyone 才能工作
【发布时间】:2021-01-17 01:08:48
【问题描述】:

我正在尝试使用 Ansible 模块(例如 https://docs.ansible.com/ansible/latest/collections/community/general/one_image_info_module.html)管理在 opennebula 上运行的虚拟机

我在运行 macOS 10.15.6 和 python 3.8.5 (http://docs.opennebula.io/5.12/integration/system_interfaces/python.html) 的 mac 上安装了 python 模块 pyone

pip3 install pyone

pip3 list | grep pyone
pyone                 5.12.4

我的剧本:

---
- hosts: localhost

  tasks:
  - name: "test"
    community.general.one_image_info:
      api_url: https://one.mycompany.com:2633/RPC2
      api_username: myusername
      api_password: mypassword
    register: result

任务失败

fatal: [localhost]: FAILED! => {"changed": false, "msg": "This module requires pyone to work!"}

ansible localhost -m setup -a filter="ansible_python" 告诉我 ansible 使用的是相同的 python 版本。

在普通的 python 脚本中,我可以毫无问题地导入 pyone,但现在我不知道去哪里调查..

我希望有人能指出我正确的方向! 非常感谢提前

P.S.:ansible --version的输出

ansible 2.10.1
  config file = /Users/fabian/projects/server-automation/ansible.cfg
  configured module search path = ['/Users/fabian/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)]

我需要安装 Pyone 和其他 python 模块以使用其他 ansible 剧本位于:/usr/local/lib/python3.8/site-packages

【问题讨论】:

  • 检查ansible localhost -m setup -a filter="ansible_python" 的输出并与您安装模块的python 版本进行比较。您可能安装在一个版本中并且ansible 是“远程”的(虽然它是本地主机...... ) 使用其他发现的版本。如果是这种情况,要么在其他版本中安装 lib,要么调整 python interpreter discovery 以便使用正确的。
  • 谢谢。可悲的是它也在使用 python 3.8.5
  • 您可以帮助解决这个问题,以及希望运行此剧本的未来同事,方法是在该任务之前添加一个任务以显式安装 pyone:- ansible.builtin.pip: name=pyone state=present;如果您已经按照您的要求安装了它,那么什么都不会改变,但是如果您使用了错误的 python(正如我们强烈怀疑的那样),或者移动到新机器,那么该任务将在尝试使用之前确保依赖关系完好无损one_image_info 正下方
  • 谢谢。这很有帮助,但在这种情况下它仍然不起作用。任务以 ok 状态结束。我卸载了 pyone 并再次运行了剧本。它安装了 pyone,但下一个任务仍然失败并出现同样的错误。

标签: python ansible opennebula


【解决方案1】:

尝试 sudo pip3 安装。为我工作:

sudo pip3 install pyone

【讨论】:

    【解决方案2】:

    我同意它看起来确实使用了错误的 python 版本。 您可以尝试将以下内容添加到您的剧本中吗?

      vars:
        ansible_python_interpreter: '/usr/bin/python3'
    

    【讨论】:

      猜你喜欢
      • 2017-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-14
      • 2021-02-09
      • 2011-02-22
      相关资源
      最近更新 更多