Add ability to use |success and |failed as Jinja2 filters.
Example: when: registered_variable|failed
This commit is contained in:
parent
4840e59b90
commit
c4a125e6d9
2 changed files with 22 additions and 1 deletions
|
@ -25,6 +25,8 @@ Core Features:
|
||||||
* external inventory script added for Spacewalk / Red Hat Satellite servers
|
* external inventory script added for Spacewalk / Red Hat Satellite servers
|
||||||
* It is now possible to feed JSON structures to --extra-vars. Pass in a JSON dictionary/hash to feed in complex data.
|
* It is now possible to feed JSON structures to --extra-vars. Pass in a JSON dictionary/hash to feed in complex data.
|
||||||
* group_vars/ and host_vars/ directories can now be kept alongside the playbook as well as inventory (or both!)
|
* group_vars/ and host_vars/ directories can now be kept alongside the playbook as well as inventory (or both!)
|
||||||
|
* more filters: ability to say {{ foo|success }} and {{ foo|failed }} and when: foo|success and when: foo|failed
|
||||||
|
* more filters: {{ path|basename }} and {{ path|dirname }}
|
||||||
|
|
||||||
Modules added:
|
Modules added:
|
||||||
|
|
||||||
|
@ -64,7 +66,6 @@ Modules removed
|
||||||
|
|
||||||
* vagrant -- can't be compatible with both versions at once, just run things though the vagrant provisioner in vagrant core
|
* vagrant -- can't be compatible with both versions at once, just run things though the vagrant provisioner in vagrant core
|
||||||
|
|
||||||
|
|
||||||
Bugfixes and Misc Changes:
|
Bugfixes and Misc Changes:
|
||||||
|
|
||||||
* service module happier if only enabled=yes|no specified and no state
|
* service module happier if only enabled=yes|no specified and no state
|
||||||
|
|
|
@ -19,6 +19,7 @@ import base64
|
||||||
import json
|
import json
|
||||||
import os.path
|
import os.path
|
||||||
import yaml
|
import yaml
|
||||||
|
from ansible import errors
|
||||||
|
|
||||||
def to_nice_yaml(*a, **kw):
|
def to_nice_yaml(*a, **kw):
|
||||||
'''Make verbose, human readable yaml'''
|
'''Make verbose, human readable yaml'''
|
||||||
|
@ -28,6 +29,20 @@ def to_nice_json(*a, **kw):
|
||||||
'''Make verbose, human readable JSON'''
|
'''Make verbose, human readable JSON'''
|
||||||
return json.dumps(*a, indent=4, sort_keys=True, **kw)
|
return json.dumps(*a, indent=4, sort_keys=True, **kw)
|
||||||
|
|
||||||
|
def failed(*a, **kw):
|
||||||
|
item = a[0]
|
||||||
|
if type(item) != dict:
|
||||||
|
raise errors.AnsibleError("|failed expects a dictionary")
|
||||||
|
rc = item.get('rc',0)
|
||||||
|
failed = item.get('failed',False)
|
||||||
|
if rc != 0 or failed:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def success(*a, **kw):
|
||||||
|
return not failed(*a, **kw)
|
||||||
|
|
||||||
class FilterModule(object):
|
class FilterModule(object):
|
||||||
''' Ansible core jinja2 filters '''
|
''' Ansible core jinja2 filters '''
|
||||||
|
|
||||||
|
@ -50,5 +65,10 @@ class FilterModule(object):
|
||||||
# path
|
# path
|
||||||
'basename': os.path.basename,
|
'basename': os.path.basename,
|
||||||
'dirname': os.path.dirname,
|
'dirname': os.path.dirname,
|
||||||
|
|
||||||
|
# failure testing
|
||||||
|
'failed' : failed,
|
||||||
|
'success' : success,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue