Ansible find object in list by value of object field

Viewed 10142

I have this structure. For each host this structure may have more or less items. In a task I want to know if there is a a module defined with a particular name.

---
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

For instance I want to know if the module_name Reporting is defined so that I include a set of tasks for it.

- 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 

How do I get this to work? Is there a better way?

1 Answers
Related