summaryrefslogtreecommitdiffstats
path: root/test/integration/targets
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2024-09-05 16:16:23 +0200
committerGitHub <noreply@github.com>2024-09-05 16:16:23 +0200
commit4fa512406bf993a570759a0c5deed20d639e51c8 (patch)
treea114c5e54de48206d7415e4bfe4f86d18ee61868 /test/integration/targets
parentrelease.py - Include pyproject.toml in git add (#83892) (diff)
downloadansible-4fa512406bf993a570759a0c5deed20d639e51c8.tar.xz
ansible-4fa512406bf993a570759a0c5deed20d639e51c8.zip
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>
Diffstat (limited to 'test/integration/targets')
-rw-r--r--test/integration/targets/loop_control/break_when.yml17
-rwxr-xr-xtest/integration/targets/loop_control/runme.sh2
2 files changed, 19 insertions, 0 deletions
diff --git a/test/integration/targets/loop_control/break_when.yml b/test/integration/targets/loop_control/break_when.yml
new file mode 100644
index 0000000000..da3de28937
--- /dev/null
+++ b/test/integration/targets/loop_control/break_when.yml
@@ -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
diff --git a/test/integration/targets/loop_control/runme.sh b/test/integration/targets/loop_control/runme.sh
index af065ea0e2..6c71aedd78 100755
--- a/test/integration/targets/loop_control/runme.sh
+++ b/test/integration/targets/loop_control/runme.sh
@@ -10,3 +10,5 @@ bar_label'
[ "$(ansible-playbook label.yml "$@" |grep 'item='|sed -e 's/^.*(item=looped_var \(.*\)).*$/\1/')" == "${MATCH}" ]
ansible-playbook extended.yml "$@"
+
+ansible-playbook break_when.yml "$@"