On Mon, 23 Mar 2020 09:42:29 -0700 (PDT)
Quentin Aveno <[email protected]> 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

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200323185022.5dd015a3%40gmail.com.

Attachment: pgpMnTRwYKHNO.pgp
Description: OpenPGP digital signature

Reply via email to