我坚持在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"