在Ansible WHEN陈述式中使用多个条件

时间:2020-06-15 14:45:23

标签: ansible conditional-statements

我坚持在Ansible 2.9.2上为WHEN设置条件。 由于某种原因,and条件似乎不适用于getent_group结果。

- getent:
    database: group
    split: ':'

- name: find user in group (does NOT work)
  debug: 
    msg: "{{item}}"
  loop: "{{ lookup('dict', getent_group) }}"
  when:
    - "'username' in item.value"
    - "'groupname' in item.key"

- name: find user in group (does NOT work)
  debug: 
    msg: "{{item}}"
  loop: "{{ lookup('dict', getent_group) }}"
  when: "'username' in item.value and 'groupname' in item.key"

- name: find user (WORKS!)
  debug: 
    msg: "{{item}}"
  loop: "{{ lookup('dict', getent_group) }}"
  when: "'username' in item.value"

- name: find group (WORKS!)
  debug: 
    msg: "{{item}}"
  loop: "{{ lookup('dict', getent_group) }}"
  when: "'groupname' in item.key"

0 个答案:

没有答案