|
|
@ -23,7 +23,6 @@ import types
|
|
|
|
import pipes
|
|
|
|
import pipes
|
|
|
|
import glob
|
|
|
|
import glob
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import collections
|
|
|
|
|
|
|
|
import crypt
|
|
|
|
import crypt
|
|
|
|
import hashlib
|
|
|
|
import hashlib
|
|
|
|
import string
|
|
|
|
import string
|
|
|
@ -35,6 +34,7 @@ import uuid
|
|
|
|
import yaml
|
|
|
|
import yaml
|
|
|
|
from jinja2.filters import environmentfilter
|
|
|
|
from jinja2.filters import environmentfilter
|
|
|
|
from distutils.version import LooseVersion, StrictVersion
|
|
|
|
from distutils.version import LooseVersion, StrictVersion
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
|
|
|
|
from ansible import errors
|
|
|
|
from ansible import errors
|
|
|
|
from ansible.utils.hashing import md5s, checksum_s
|
|
|
|
from ansible.utils.hashing import md5s, checksum_s
|
|
|
@ -182,51 +182,6 @@ def ternary(value, true_val, false_val):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return false_val
|
|
|
|
return false_val
|
|
|
|
|
|
|
|
|
|
|
|
def unique(a):
|
|
|
|
|
|
|
|
if isinstance(a,collections.Hashable):
|
|
|
|
|
|
|
|
c = set(a)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
c = []
|
|
|
|
|
|
|
|
for x in a:
|
|
|
|
|
|
|
|
if x not in c:
|
|
|
|
|
|
|
|
c.append(x)
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def intersect(a, b):
|
|
|
|
|
|
|
|
if isinstance(a,collections.Hashable) and isinstance(b,collections.Hashable):
|
|
|
|
|
|
|
|
c = set(a) & set(b)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
c = unique(filter(lambda x: x in b, a))
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def difference(a, b):
|
|
|
|
|
|
|
|
if isinstance(a,collections.Hashable) and isinstance(b,collections.Hashable):
|
|
|
|
|
|
|
|
c = set(a) - set(b)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
c = unique(filter(lambda x: x not in b, a))
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def symmetric_difference(a, b):
|
|
|
|
|
|
|
|
if isinstance(a,collections.Hashable) and isinstance(b,collections.Hashable):
|
|
|
|
|
|
|
|
c = set(a) ^ set(b)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
c = unique(filter(lambda x: x not in intersect(a,b), union(a,b)))
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def union(a, b):
|
|
|
|
|
|
|
|
if isinstance(a,collections.Hashable) and isinstance(b,collections.Hashable):
|
|
|
|
|
|
|
|
c = set(a) | set(b)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
c = unique(a + b)
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def min(a):
|
|
|
|
|
|
|
|
_min = __builtins__.get('min')
|
|
|
|
|
|
|
|
return _min(a);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def max(a):
|
|
|
|
|
|
|
|
_max = __builtins__.get('max')
|
|
|
|
|
|
|
|
return _max(a);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def version_compare(value, version, operator='eq', strict=False):
|
|
|
|
def version_compare(value, version, operator='eq', strict=False):
|
|
|
|
''' Perform a version comparison on a value '''
|
|
|
|
''' Perform a version comparison on a value '''
|
|
|
@ -386,14 +341,6 @@ class FilterModule(object):
|
|
|
|
'ternary': ternary,
|
|
|
|
'ternary': ternary,
|
|
|
|
|
|
|
|
|
|
|
|
# list
|
|
|
|
# list
|
|
|
|
'unique' : unique,
|
|
|
|
|
|
|
|
'intersect': intersect,
|
|
|
|
|
|
|
|
'difference': difference,
|
|
|
|
|
|
|
|
'symmetric_difference': symmetric_difference,
|
|
|
|
|
|
|
|
'union': union,
|
|
|
|
|
|
|
|
'min' : min,
|
|
|
|
|
|
|
|
'max' : max,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# version comparison
|
|
|
|
# version comparison
|
|
|
|
'version_compare': version_compare,
|
|
|
|
'version_compare': version_compare,
|
|
|
|
|
|
|
|
|
|
|
|