提问人:Stephen P. Schaefer 提问时间:9/10/2023 更新时间:9/10/2023 访问量:43
ansible 如何搜索模块的命名空间?
How does ansible search namespaces for modules?
问:
我需要编写与多个版本的 ansible 兼容的 ansible 代码。旧版本的 ansible 没有命名空间,而较新版本的 ansible 有命名空间。在一个实例中,一个角色调用了一个“ansible.builtin.yum”模块,该模块在早期版本的 ansible 中失败了。就目前而言,删除前缀就足够了。命名空间行为记录在哪里?据推测,无前缀的模块名称是在命名空间列表中搜索的 - 该列表是什么?是否有命名空间设计文档?我能找到的最接近命名空间设计文档的是 https://galaxy.ansible.com/docs/contributing/namespaces.html,它做出了无效的用例假设。
现在,从此类前缀模块的名称中删除“ansible.builtin.”是有效的,但我想了解何时停止与较新版本的 ansible 一起使用的命名空间机制。
答:
2赞
Vladimir Botka
9/10/2023
#1
你得到什么取决于配置。看
例如,如果您使用 yum
- hosts: all
tasks:
- yum:
name: nginx
找到的第一个将被使用
shell> ansible-doc -t module -l | grep yum
ansible.builtin.yum
Manages packages with the ...
ansible.builtin.yum_repository
Add or re...
community.general.yum_versionlock
Locks / unlocks an installed package(s) from being updated b...
在标准的 Ansible 安装中,已安装的模块中只有一个 yum。因此,文档说:
在大多数情况下,您可以使用短模块名称 yum
相同的规则将应用于您的自定义模块:
下一个:在快速文档中显示类的命名空间
评论