From 08db37a524fc574df3e50eb71aeffa8e583de799 Mon Sep 17 00:00:00 2001 From: infrascripting Date: Thu, 22 Jun 2017 17:38:03 -0400 Subject: [PATCH 1/2] Add conditional example to block Use-case I stumbled on while searching for a way to conditionally skip the remainder of a role without failing. Reference: https://github.com/ansible/ansible/issues/1476#issuecomment-195519223 https://github.com/ansible/ansible/issues/1476#issuecomment-213946467 I'm sure it could use a bit more explanation, I'm just not sure what would need to be said. --- docs/docsite/rst/playbooks_blocks.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/docsite/rst/playbooks_blocks.rst b/docs/docsite/rst/playbooks_blocks.rst index 5d2f668d470ca4..4558b510f69ab7 100644 --- a/docs/docsite/rst/playbooks_blocks.rst +++ b/docs/docsite/rst/playbooks_blocks.rst @@ -80,6 +80,25 @@ Another example is how to run handlers after an error occurred : - name: run me even after an error debug: msg='this handler runs even on error' + +Conditional Execution +````````````````````` + +Blocks allow groups of tasks to be skipped based on a conditional test. + +.. code-block:: YAML + :emphasize-lines: 2,6,10 + :caption: Block error handling example + + tasks: + - block: + - debug: var=msg + when: true + when: true + + +Any and all of the tasks in the ``block`` would only be executed if the condition being tested was true. + .. seealso:: :doc:`playbooks` From f4e7a0bdb741f4e55a523742aef3621f8afb19bc Mon Sep 17 00:00:00 2001 From: infrascripting Date: Thu, 22 Jun 2017 17:39:20 -0400 Subject: [PATCH 2/2] Fix example yaml metadata --- docs/docsite/rst/playbooks_blocks.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/docsite/rst/playbooks_blocks.rst b/docs/docsite/rst/playbooks_blocks.rst index 4558b510f69ab7..1799b4e1ea1a2a 100644 --- a/docs/docsite/rst/playbooks_blocks.rst +++ b/docs/docsite/rst/playbooks_blocks.rst @@ -87,8 +87,7 @@ Conditional Execution Blocks allow groups of tasks to be skipped based on a conditional test. .. code-block:: YAML - :emphasize-lines: 2,6,10 - :caption: Block error handling example + :caption: Block conditional execution example tasks: - block: