summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Whittington <github@whittington.net.nz>2016-08-26 04:52:52 +1200
committerMatt Davis <nitzmahone@users.noreply.github.com>2016-08-25 09:52:52 -0700
commit2b3a22fdbaab32cb581c6cfbf7b3c7285c415c29 (patch)
tree7cf4e9d93c5e4fe0d3c4a07f84645ad27cf0fd73
parentd29e9d7d3c8fea629e40cfe7bf90747c9b70e771 (diff)
downloadansible-2b3a22fdbaab32cb581c6cfbf7b3c7285c415c29.tar.gz
Document when clause list of conditions (#17206)
The 'when' clause supports a list of conditions, applying a logical 'and' to the conditions (i.e. requiring all of them to be true). This can be useful for legibility sometimes, allowing distinct conditions to be listed on separate lines.
-rw-r--r--docsite/rst/playbooks_conditionals.rst9
1 files changed, 9 insertions, 0 deletions
diff --git a/docsite/rst/playbooks_conditionals.rst b/docsite/rst/playbooks_conditionals.rst
index cf6ed50a37..4db99fb6fa 100644
--- a/docsite/rst/playbooks_conditionals.rst
+++ b/docsite/rst/playbooks_conditionals.rst
@@ -38,6 +38,15 @@ You can also use parentheses to group conditions::
when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6") or
(ansible_distribution == "Debian" and ansible_distribution_major_version == "7")
+Multiple conditions that all need to be true (a logical 'and') can also be specified as a list::
+
+ tasks:
+ - name: "shut down CentOS 6 systems"
+ command: /sbin/shutdown -t now
+ when:
+ - ansible_distribution == "CentOS"
+ - ansible_distribution_major_version == "6"
+
A number of Jinja2 "filters" can also be used in when statements, some of which are unique
and provided by Ansible. Suppose we want to ignore the error of one statement and then
decide to do something conditionally based on success or failure::