mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #4437 from sergevanginderachter/changed_filter
Implement a |changed filter plugin
This commit is contained in:
commit
a9225d0c7a
1 changed files with 23 additions and 1 deletions
|
@ -34,6 +34,7 @@ def to_nice_json(*a, **kw):
|
|||
return json.dumps(*a, indent=4, sort_keys=True, **kw)
|
||||
|
||||
def failed(*a, **kw):
|
||||
''' Test if task result yields failed '''
|
||||
item = a[0]
|
||||
if type(item) != dict:
|
||||
raise errors.AnsibleFilterError("|failed expects a dictionary")
|
||||
|
@ -45,9 +46,27 @@ def failed(*a, **kw):
|
|||
return False
|
||||
|
||||
def success(*a, **kw):
|
||||
''' Test if task result yields success '''
|
||||
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")
|
||||
if not 'changed' in item:
|
||||
changed = False
|
||||
if ('results' in item # some modules return a 'results' key
|
||||
and type(item['results']) == list
|
||||
and type(item['results'][0]) == dict):
|
||||
for result in item['results']:
|
||||
changed = changed or result.get('changed', False)
|
||||
else:
|
||||
changed = item.get('changed', False)
|
||||
return changed
|
||||
|
||||
def skipped(*a, **kw):
|
||||
''' Test if task result yields skipped '''
|
||||
item = a[0]
|
||||
if type(item) != dict:
|
||||
raise errors.AnsibleFilterError("|skipped expects a dictionary")
|
||||
|
@ -106,6 +125,9 @@ class FilterModule(object):
|
|||
'failed' : failed,
|
||||
'success' : success,
|
||||
|
||||
# changed testing
|
||||
'changed' : changed,
|
||||
|
||||
# skip testing
|
||||
'skipped' : skipped,
|
||||
|
||||
|
|
Loading…
Reference in a new issue