mirror of https://github.com/ansible/ansible.git
loop_control "early exit" feature (#62151)
* 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>pull/83908/head
parent
e3ccdaaa2e
commit
4fa512406b
@ -0,0 +1,2 @@
|
||||
minor_changes:
|
||||
- loop_control - add a break_when option to to break out of a task loop early based on Jinja2 expressions (https://github.com/ansible/ansible/issues/83442).
|
@ -0,0 +1,17 @@
|
||||
- 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
|
Loading…
Reference in New Issue