2
我有這樣的結構。對於每個主機,這個結構可能有更多或更少的項目。在一個任務中,我想知道是否有一個用特定名稱定義的模塊。Ansible通過對象字段的值在列表中找到對象
---
web_module_list:
- module_name: LaunchPad
module_version: 1.4.0
- module_name: Manager
module_version: 1.6.0
- module_name: NetworkInventory
module_version: 1.1.4
- module_name: Reporting
module_version: 1.0.18
- module_name: TriadJ
module_version: 4.1.0-1.1.7
比如我想知道,如果MODULE_NAME報告定義,這樣我包括一組它的任務。
- set_fact:
reporting: if the web_module_list contains an item with module_name Reporting then true else false
woprinting: if the web_module_list contains an item with module_name WorkOrderPrinting then true else false
- name: If the reporting module is listed in inventory then execute its tasks
include: reporting.yml
when: reporting
- name: If the work order printing module is listed in inventory then execute its tasks
include: woprinting.yml
when: woprinting
我如何得到這個工作? 有沒有更好的方法?