I'm quite new to Ansible, so please be patient. I'm trying to come up with an elegant way to populate a list. Some of the items should be in the list unconditionally, for example, item1. Some of them would be added to the list if "when" conditions are met. So far I got this and it is not working, I assume it just overrides item1 with item2 and 3. Also, it starts looking ugly the more items you add. Has anyone had experience with populating ansible lists conditionally?
- name: Add items to list
set_fact:
items_list: ["item1"]
with_items:
- item2
when:
- condition1 is defined
- condition3 is defined
- item3
when:
- condition 4 is defined
Best Answer
or