From 0c449598009fb440e150e9578ab3a18958cfca41 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 15 Mar 2017 18:09:25 -0400 Subject: [PATCH] added new tests any and all (#22665) * added new tests any and all * updated code names --- CHANGELOG.md | 8 +++++++- docs/docsite/rst/playbooks_tests.rst | 21 +++++++++++++++++++++ lib/ansible/plugins/test/core.py | 3 +++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a2a087b8..a322007e68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ Ansible Changes By Release ========================== -## 2.3 TBD - ACTIVE DEVELOPMENT +## 2.4 "Dancing Days" - ACTIVE DEVELOPMENT + +#### New: Tests +- any : true if any element is true +- all: true if all elements are true + +## 2.3 "Ramble On" - RELEASE CANDIDATE ### Major Changes * Documented and renamed the previously released 'single var vaulting' feature, allowing user to use vault encryption for single variables in a normal YAML vars file. diff --git a/docs/docsite/rst/playbooks_tests.rst b/docs/docsite/rst/playbooks_tests.rst index a420e578cc..27f6cb340a 100644 --- a/docs/docsite/rst/playbooks_tests.rst +++ b/docs/docsite/rst/playbooks_tests.rst @@ -83,6 +83,27 @@ To see if a list includes or is included by another list, you can use 'issubset' .. _path_tests: +.. versionadded:: 2.4 + +You can use `any` and `all` to check if any or all elements in a list are true or not:: + + vars: + mylist: + - 1 + - 3 == 3 + - True + myotherlist: + - False + - True + tasks: + + - debug: msg="all are true!" + when: mylist is all + + - debug: msg="at least one is true" + when: myotherlist|any + + Testing paths ````````````` diff --git a/lib/ansible/plugins/test/core.py b/lib/ansible/plugins/test/core.py index 19f6964f15..a8bdbf1c2b 100644 --- a/lib/ansible/plugins/test/core.py +++ b/lib/ansible/plugins/test/core.py @@ -137,4 +137,7 @@ class TestModule(object): # version comparison 'version_compare': version_compare, + # lists + 'any': any, + 'all': all, }