* add a loop_control break_when directive to break out of a loop after any item
* remove loop var as normal exit would
* example usage:
- name: generate a random password up to 10 times, until it matches the policy
set_fact:
password: "{{ lookup('password', '/dev/null', chars=character_set, length=length) }}"
loop: "{{ range(0, 10) }}"
loop_control:
break_when:
- password is match(password_policy)
Co-authored-by: s-hertel <19572925+s-hertel@users.noreply.github.com>
18 lines
310 B
YAML
18 lines
310 B
YAML
- hosts: localhost
|
|
gather_facts: false
|
|
tasks:
|
|
- debug: var=item
|
|
changed_when: false
|
|
loop:
|
|
- 1
|
|
- 2
|
|
- 3
|
|
- 4
|
|
loop_control:
|
|
break_when: item >= 2
|
|
register: untiltest
|
|
|
|
- assert:
|
|
that:
|
|
- untiltest['results']|length == 2
|