From 3ca654ad9ade1ce2745f4b3496d3a1683ace2ce5 Mon Sep 17 00:00:00 2001 From: Strahinja Kustudic Date: Sun, 5 Oct 2014 19:54:31 +0200 Subject: [PATCH] Added an example for paretheses --- docsite/rst/playbooks_conditionals.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docsite/rst/playbooks_conditionals.rst b/docsite/rst/playbooks_conditionals.rst index a00ec916c41..cdaf54f5ea4 100644 --- a/docsite/rst/playbooks_conditionals.rst +++ b/docsite/rst/playbooks_conditionals.rst @@ -26,6 +26,14 @@ It's actually pretty simple:: command: /sbin/shutdown -t now when: ansible_os_family == "Debian" +You can also use parentheses to group conditions:: + + tasks: + - name: "shutdown CentOS 6 and 7 systems" + command: /sbin/shutdown -t now + when: ansible_distribution == "CentOS" and + (ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7") + 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::