def oo_ami_selector(data, image_name):
 if (not isinstance(data, list)):
  raise errors.AnsibleFilterError('|failed expects first param is a list')
 if (not data):
  return None
 elif ((image_name is None) or (not image_name.endswith('_*'))):
  ami = sorted(data, key=itemgetter('name'), reverse=True)[0]
  return ami['ami_id']
 else:
  ami_info = [(ami, ami['name'].split('_')[(-1)]) for ami in data]
  ami = sorted(ami_info, key=itemgetter(1), reverse=True)[0][0]
  return ami['ami_id']

def oo_ami_selector ( data , image_name ) : if ( not isinstance ( data , list ) ) : raise errors . AnsibleFilterError ( '|failed expects first param is a list' ) if ( not data ) : return None elif ( ( image_name is None ) or ( not image_name . endswith ( '_*' ) ) ) : ami = sorted ( data , key = itemgetter ( 'name' ) , reverse = True ) [ 0 ] return ami [ 'ami_id' ] else : ami_info = [ ( ami , ami [ 'name' ] . split ( '_' ) [ ( - 1 ) ] ) for ami in data ] ami = sorted ( ami_info , key = itemgetter ( 1 ) , reverse = True ) [ 0 ] [ 0 ] return ami [ 'ami_id' ]
this takes a list of amis and an image name and attempts to return the latest ami .