---
- name: Fetch list of inventories from Tower
  uri:
    force_basic_auth : yes
    url_username     : "{{ __tower_user}}"
    url_password     : "{{ __tower_pass}}"
    url              : "{{ __tower_url }}/api/v2/inventories/"
    validate_certs   : no
    return_content   : no
    body_format      : json
  register           : r_get_inv_list


- name: Build inventory list from Tower results
  set_fact:
    r_inventory_list : "{{ r_inventory_list | default([]) + [item.name] }}"
  loop               : "{{ r_get_inv_list.json.results }}"
  loop_control       :
    label            : "{{ item.name }}"


- name: Register inventory ID if available
  set_fact:
    r_inv_id : "{{ lookup('template', 'templates/get_inventory_id.j2') }}"
  when       :
    - r_inventory_list is defined
    - __inventory in r_inventory_list


...
