From 906746b1f0d0b516ba6ebbeefc9c307c3fbc44c7 Mon Sep 17 00:00:00 2001 From: Stoned Elipot Date: Sun, 7 Jul 2013 21:39:09 +0200 Subject: [PATCH] Add Jinja2 filter 'skipped' to test for a registered variable from a skipped task --- docsite/latest/rst/playbooks2.rst | 2 ++ lib/ansible/runner/filter_plugins/core.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/docsite/latest/rst/playbooks2.rst b/docsite/latest/rst/playbooks2.rst index 30fd4cc82c..d2b0518168 100644 --- a/docsite/latest/rst/playbooks2.rst +++ b/docsite/latest/rst/playbooks2.rst @@ -300,6 +300,8 @@ decide to do something conditionally based on success or failure:: when: result|failed - action: command /bin/something_else when: result|success + - action: command /bin/still/something_else + when: result|skipped As a reminder, to see what derived variables are available, you can do:: diff --git a/lib/ansible/runner/filter_plugins/core.py b/lib/ansible/runner/filter_plugins/core.py index 107c5e1fcb..675f5e8522 100644 --- a/lib/ansible/runner/filter_plugins/core.py +++ b/lib/ansible/runner/filter_plugins/core.py @@ -44,6 +44,13 @@ def failed(*a, **kw): def success(*a, **kw): return not failed(*a, **kw) +def skipped(*a, **kw): + item = a[0] + if type(item) != dict: + raise errors.AnsibleError("|skipped expects a dictionary") + skipped = item.get('skipped', False) + return skipped + def mandatory(a): ''' Make a variable mandatory ''' if not a: @@ -88,6 +95,9 @@ class FilterModule(object): 'failed' : failed, 'success' : success, + # skip testing + 'skipped' : skipped, + # variable existence 'mandatory': mandatory,