【问题标题】:Ansible Python API plugin not found未找到 Ansible Python API 插件
【发布时间】:2021-04-17 06:43:28
【问题描述】:

我一直在尝试使用 Ansible Python API,如他们的 official docs here 中所述。问题是,当我调用 main() 时,Ansible 返回一个错误:

the connection plugin '<class 'ansible.utils.sentinel.Sentinel'>' was not found

我正在运行 ansible-base 版本 2.10.8。

我已经被这个问题困扰了两天了。我在 Ansible 的 github page here 看到有人遇到同样的问题,他们似乎甚至不支持自己的 Python API。

谁能建议我如何解决这个问题?

【问题讨论】:

  • it seems they don't support their own Python API => 在您在第一段中链接的文档顶部的注释中:This API is intended for internal Ansible use. Ansible may make changes to this API at any time that could break backward compatibility with older versions of the API. Because of this, external use is not supported by Ansible
  • 既然你问了一个建议:不要在你的外部项目中使用 ansible 内部 python API。
  • 是的。我知道这一点,并且我确实尝试过首先与 ansible-runner 合作。但是,ansible-runner 在 stdout 键中返回一组带有 ansible 结果的嵌套字典。这不完全是我需要的。这是说使用实际的 API 是没有希望的吗?
  • 是的,我已经尝试过 ansible-runner 解决方案。
  • 好吧,这就是我的想法:我们遇到了 X/Y 问题。将 stdout 回调更改为适合您的需求。这里有一些信息docs.ansible.com/ansible/latest/plugins/callback.html。另请参阅此答案:stackoverflow.com/a/50017860/9401096

标签: python-3.x ansible


【解决方案1】:

我解决了我的问题,但我花了几天时间进行大量调试。由于我不会在这里讨论的原因(我的技术主管强迫我),我不得不使用这个 API。 我建议不要在 Ansible 开发之外使用它。总的来说,这是一种耗时且糟糕的体验。

此错误掩盖了真正的问题。如果您看到此异常,则表示其他地方有问题。它通常在task_executor.py 内。检查您的代码并确保您没有拼写错误并且提供了所有参数。 Python API 似乎缺乏正确的异常处理,因此异常消息有些混乱。

对我来说,这是因为我没有为 context.CLIARGS 提供 verbosity 参数,Ansible 文档中提供的简短示例也缺少该参数。

【讨论】:

  • 谢谢。在我问这个问题的时候,我也读了这篇文章。这很棒,给了我一个更好的主意,但过了一段时间你就真的靠自己了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-03
相关资源
最近更新 更多