|
|
@ -23,8 +23,10 @@ import types
|
|
|
|
import pipes
|
|
|
|
import pipes
|
|
|
|
import glob
|
|
|
|
import glob
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
|
|
|
|
import operator as py_operator
|
|
|
|
from ansible import errors
|
|
|
|
from ansible import errors
|
|
|
|
from ansible.utils import md5s
|
|
|
|
from ansible.utils import md5s
|
|
|
|
|
|
|
|
from distutils.version import LooseVersion, StrictVersion
|
|
|
|
|
|
|
|
|
|
|
|
def to_nice_yaml(*a, **kw):
|
|
|
|
def to_nice_yaml(*a, **kw):
|
|
|
|
'''Make verbose, human readable yaml'''
|
|
|
|
'''Make verbose, human readable yaml'''
|
|
|
@ -151,6 +153,33 @@ def symmetric_difference(a, b):
|
|
|
|
def union(a, b):
|
|
|
|
def union(a, b):
|
|
|
|
return set(a).union(b)
|
|
|
|
return set(a).union(b)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def version_compare(value, version, operator='eq', strict=False):
|
|
|
|
|
|
|
|
''' Perform a version comparison on a value '''
|
|
|
|
|
|
|
|
op_map = {
|
|
|
|
|
|
|
|
'==': 'eq', '=': 'eq', 'eq': 'eq',
|
|
|
|
|
|
|
|
'<': 'lt', 'lt': 'lt',
|
|
|
|
|
|
|
|
'<=': 'le', 'le': 'le',
|
|
|
|
|
|
|
|
'>': 'gt', 'gt': 'gt',
|
|
|
|
|
|
|
|
'>=': 'ge', 'ge': 'ge',
|
|
|
|
|
|
|
|
'!=': 'ne', '<>': 'ne', 'ne': 'ne'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if strict:
|
|
|
|
|
|
|
|
Version = StrictVersion
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
Version = LooseVersion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if operator in op_map:
|
|
|
|
|
|
|
|
operator = op_map[operator]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
raise errors.AnsibleFilterError('Invalid operator type')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
method = getattr(py_operator, operator)
|
|
|
|
|
|
|
|
return method(Version(str(value)), Version(str(version)))
|
|
|
|
|
|
|
|
except Exception, e:
|
|
|
|
|
|
|
|
raise errors.AnsibleFilterError('Version comparison: %s' % e)
|
|
|
|
|
|
|
|
|
|
|
|
class FilterModule(object):
|
|
|
|
class FilterModule(object):
|
|
|
|
''' Ansible core jinja2 filters '''
|
|
|
|
''' Ansible core jinja2 filters '''
|
|
|
|
|
|
|
|
|
|
|
@ -213,5 +242,8 @@ class FilterModule(object):
|
|
|
|
'difference': difference,
|
|
|
|
'difference': difference,
|
|
|
|
'symmetric_difference': symmetric_difference,
|
|
|
|
'symmetric_difference': symmetric_difference,
|
|
|
|
'union': union,
|
|
|
|
'union': union,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# version comparison
|
|
|
|
|
|
|
|
'version_compare': version_compare,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|