I'm trying to have list of paths.
The variables folder (web_folder, app_folder or db_folder ) may be undefined and is expected to be undefined.
In this case I just don't want the undefined value in the the list.
- set_fact: root_paths="{{ root_paths | default([]) + [ item ] }}"
loop:
- "{{ web_folder }}"
- "{{ app_folder }}"
- "{{ db_folder }}"
when: item is defined
When I do this I get an error message 'The task includes an option with an undefined variable.'
I can make this work if I define default values e.g. '-' and replace the when condition with
when: item != '-'
I don't like this solution.
I tried a few things like
- 'when: vars[item] is undefined' from this post, but it didn't work for me.
- I also replaces 'loop' with 'with_items' didn't work either
Any suggestions?