Home > database >  How remove a item from a list with jinja2
How remove a item from a list with jinja2

Time:10-22

Ansible: 2.4.9

I like to execute a task on to server list from my "groups" magic var without "server_summer03".

Code:

host: all
tasks:
  - debug:
      msg: "{{ ansible_host }}"
    vars:
      ansible_host: "{{ item | reject('search', 'server_summer03') }}"
    with_items:
      - "{{ groups['summer'] }}"

But the output is:

msg: '<generator object _select or _reject at 0x7f013ca....

CodePudding user response:

you could use when:

host: all
tasks:
  - debug:
      msg: "{{ ansible_host }}"
    vars:
      ansible_host: "{{ item }}
    when: item != 'server_summer03'
    with_items:
      - "{{ groups['summer'] }}"
  • Related