mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #3463 from stoned/filterskipped
Add Jinja2 filter 'skipped' to test for a registered variable from a ski...
This commit is contained in:
commit
90dfc115d6
2 changed files with 12 additions and 0 deletions
|
@ -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::
|
||||
|
|
|
@ -45,6 +45,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:
|
||||
|
@ -93,6 +100,9 @@ class FilterModule(object):
|
|||
'failed' : failed,
|
||||
'success' : success,
|
||||
|
||||
# skip testing
|
||||
'skipped' : skipped,
|
||||
|
||||
# variable existence
|
||||
'mandatory': mandatory,
|
||||
|
||||
|
|
Loading…
Reference in a new issue