gpt4 book ai didi

python - 开发的 Ansible 模块可以包含或扩展 Ansible Core 模块吗?

转载 作者:太空狗 更新时间:2023-10-29 20:21:45 25 4
gpt4 key购买 nike

我正在开发一个 Ansible 模块,该模块生成一个 url,从我的内部工件中获取(如 get_url)该 url 的 tarball,然后将其提取。我想知道是否有办法在我的模块中包含或扩展 get_url Ansible 核心模块。我不能在多个步骤中进行此操作,因为正在使用的 url 是从 git 哈希生成的,需要进行多步搜索。

如果没有办法,我可能会复制整个 get_url 模块并在我的模块中使用它,但我想避免这种情况。

我想做这样的事情:

module_json_response = module.get_module('get_url').issue_command('url=http://myartifactory.com/my_artifact.tar.gz dest=/path/to/local/my_artifact.tar.gz' );

我对 Ansible 的理解是它上传正在使用的模块并执行它,包括不支持或未记录的另一个模块。

在此先感谢您的帮助。

最佳答案

引用 Michael DeHaan 的帖子 here :

Generally speaking, Ansible allows sharing code through "lib/ansible/module_common.py" to make writing functionality easier.

It does not, however, make it possible for one module to call another, which has not, to date, really been needed -- that's not entirely true, we used to have something like this for file and copy until we got smart and moved the file attribute code into common :)

It seems like since url access is frequent enough we could make a common function in module common for url downloads -- IF we modify the get_url code to also use it so we aren't repeating ourselves.

他后来跟进了:

You can access the way template works by writing an action plugin, but it's more involved than writing a simple client module.

+1 to moving get_url code into common, that's come up a few times.

关于python - 开发的 Ansible 模块可以包含或扩展 Ansible Core 模块吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15816952/

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