def oo_collect(data, attribute=None, filters=None):
 if (not isinstance(data, list)):
  raise errors.AnsibleFilterError('|failed expects to filter on a List')
 if (not attribute):
  raise errors.AnsibleFilterError('|failed expects attribute to be set')
 if (filters is not None):
  if (not isinstance(filters, dict)):
   raise errors.AnsibleFilterError('|failed expects filter to be a dict')
  retval = [get_attr(d, attribute) for d in data if all([(d.get(key, None) == filters[key]) for key in filters])]
 else:
  retval = [get_attr(d, attribute) for d in data]
 retval = [val for val in retval if (val is not None)]
 return retval

def oo_collect ( data , attribute = None , filters = None ) : if ( not isinstance ( data , list ) ) : raise errors . AnsibleFilterError ( '|failed expects to filter on a List' ) if ( not attribute ) : raise errors . AnsibleFilterError ( '|failed expects attribute to be set' ) if ( filters is not None ) : if ( not isinstance ( filters , dict ) ) : raise errors . AnsibleFilterError ( '|failed expects filter to be a dict' ) retval = [ get_attr ( d , attribute ) for d in data if all ( [ ( d . get ( key , None ) == filters [ key ] ) for key in filters ] ) ] else : retval = [ get_attr ( d , attribute ) for d in data ] retval = [ val for val in retval if ( val is not None ) ] return retval
this takes a list of dict and collects all attributes specified into a list .