开发的Ansible模块可以包括或扩展Ansible核心模块吗?

2024-09-27 22:19:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发一个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的理解是它上载正在使用的模块并执行它,包括另一个不受支持或没有文档记录的模块。在

提前谢谢你的帮助。在


Tags: 模块方法giturl核心getmy步骤
1条回答
网友
1楼 · 发布于 2024-09-27 22:19:02

引用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.

相关问题 更多 >

    热门问题