【发布时间】:2021-03-04 01:37:51
【问题描述】:
堆栈:
- Git 存储库
- Ansible AWX,具体来说,AzureRM Inventory Plugin
问题:只有当虚拟机具有特定标签并且该标签具有特定价值时,我才需要在库存中导入虚拟机。
背景: Azure Inventory 插件有一个过滤器“exclude_host_filters”,下面的文档中提供了示例:
# excludes a host from the inventory when any of these expressions is true, can refer to any vars defined on the host
exclude_host_filters:
# excludes hosts in the eastus region
- location in ['eastus']
# excludes hosts that are powered off
- powerstate != 'running'
问题:我正在尝试在排除主机过滤器中使用标签。逻辑上我需要:
- 过滤所有带有“所有者”标签的主机。
- 然后过滤所有标签为“owner”且值为“testing_ansible”的主机。
这是我尝试做的:
exclude_host_filters:
- if tags.owner is defined
- tags.owner != 'testing_ansible'
我也尝试了其他过滤器,但没有奏效。文档需要 jinja2 格式。 如何检查标签是否存在以及是否具有一定的价值导入主机?
【问题讨论】:
标签: ansible ansible-inventory ansible-awx