On Mon, 23 Mar 2020 09:42:29 -0700 (PDT)
Quentin Aveno <
aori...@gmail.com> wrote:
> Is there any way to omit a item in a list at the declaration ?
>
> - name: "Test"
> hosts: localhost
> vars:
> test1: false
> test2:
> - name: test21
> includes:
> - { file: "file221.j2", path: "/somewhere/" }
> - { file: "file222.j2", path: "/somewhere/" }
> - "{{ ( test1 | ternary ({ 'file': 'file223.j2', 'path':
> '/somewhere/' }, *omit*) ) }}"
Adding the item conditionally seems to be easier, I think
vars:
test1: false
list1:
- {file: "file221.j2", path: "/somewhere/"}
- {file: "file222.j2", path: "/somewhere/"}
list2: |
{% if test1 %}
[{{ list1 }} + [{'file': 'file223.j2', 'path': '/somewhere/'}]]
{% else %}
{{ list1 }}
{% endif %}
test2:
- name: test21
includes: "{{ list2 }}"
HTH,
-vlado