CH06
CH06

Reputation: 167

How remove a item from a list with jinja2

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....

Upvotes: 0

Views: 2228

Answers (1)

Frenchy
Frenchy

Reputation: 16997

you could use when:

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

Upvotes: 1

Related Questions