|
|
@ -488,22 +488,6 @@ def flatten(mylist, levels=None):
|
|
|
|
return ret
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def dict_slice(mydict, keys):
|
|
|
|
|
|
|
|
''' takes a dictionary and a list of keys and returns a list of values corresponding to those keys, if they exist '''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not isinstance(mydict, MutableMapping):
|
|
|
|
|
|
|
|
raise AnsibleFilterError("The slice filter requires a mapping to operate on, got a %s." % type(mydict))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not isinstance(keys, MutableSequence):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(keys, string_types):
|
|
|
|
|
|
|
|
keys = [keys]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
AnsibleFilterError("The slice filter requires a key or list of keys, got %s instead." % type(keys))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return [mydict[key] for key in keys if key in mydict]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FilterModule(object):
|
|
|
|
class FilterModule(object):
|
|
|
|
''' Ansible core jinja2 filters '''
|
|
|
|
''' Ansible core jinja2 filters '''
|
|
|
|
|
|
|
|
|
|
|
@ -590,5 +574,4 @@ class FilterModule(object):
|
|
|
|
'combine': combine,
|
|
|
|
'combine': combine,
|
|
|
|
'extract': extract,
|
|
|
|
'extract': extract,
|
|
|
|
'flatten': flatten,
|
|
|
|
'flatten': flatten,
|
|
|
|
'slice': dict_slice,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|