mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Implement a |changed filter plugin
This commit is contained in:
parent
16947041d1
commit
e5d45311f9
1 changed files with 14 additions and 1 deletions
|
@ -34,7 +34,8 @@ def to_nice_json(*a, **kw):
|
||||||
return json.dumps(*a, indent=4, sort_keys=True, **kw)
|
return json.dumps(*a, indent=4, sort_keys=True, **kw)
|
||||||
|
|
||||||
def failed(*a, **kw):
|
def failed(*a, **kw):
|
||||||
item = a[0]
|
''' Test if task result yields failed '''
|
||||||
|
item = a[0]
|
||||||
if type(item) != dict:
|
if type(item) != dict:
|
||||||
raise errors.AnsibleFilterError("|failed expects a dictionary")
|
raise errors.AnsibleFilterError("|failed expects a dictionary")
|
||||||
rc = item.get('rc',0)
|
rc = item.get('rc',0)
|
||||||
|
@ -45,9 +46,18 @@ def failed(*a, **kw):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def success(*a, **kw):
|
def success(*a, **kw):
|
||||||
|
''' Test if task result yields success '''
|
||||||
return not failed(*a, **kw)
|
return not failed(*a, **kw)
|
||||||
|
|
||||||
|
def changed(*a, **kw):
|
||||||
|
''' Test if task result yields changed '''
|
||||||
|
item = a[0]
|
||||||
|
if type(item) != dict:
|
||||||
|
raise errors.AnsibleFilterError("|changed expects a dictionary")
|
||||||
|
return item.get('changed', False)
|
||||||
|
|
||||||
def skipped(*a, **kw):
|
def skipped(*a, **kw):
|
||||||
|
''' Test if task result yields skipped '''
|
||||||
item = a[0]
|
item = a[0]
|
||||||
if type(item) != dict:
|
if type(item) != dict:
|
||||||
raise errors.AnsibleFilterError("|skipped expects a dictionary")
|
raise errors.AnsibleFilterError("|skipped expects a dictionary")
|
||||||
|
@ -106,6 +116,9 @@ class FilterModule(object):
|
||||||
'failed' : failed,
|
'failed' : failed,
|
||||||
'success' : success,
|
'success' : success,
|
||||||
|
|
||||||
|
# changed testing
|
||||||
|
'changed' : changed,
|
||||||
|
|
||||||
# skip testing
|
# skip testing
|
||||||
'skipped' : skipped,
|
'skipped' : skipped,
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue