---
- name: Get amphora flavor info
  become: true
  kolla_toolbox:
    container_engine: "{{ kolla_container_engine }}"
    module_name: openstack.cloud.compute_flavor_info
    module_args:
      auth: "{{ octavia_user_auth }}"
      cacert: "{{ openstack_cacert }}"
      endpoint_type: "{{ openstack_interface }}"
      region_name: "{{ openstack_region_name }}"
      name: "{{ octavia_amp_flavor.name }}"
  run_once: True
  check_mode: false
  delegate_to: "{{ groups['octavia-api'][0] }}"
  register: flavor_results

- name: Get {{ octavia_service_auth_project }} project id
  become: True
  kolla_toolbox:
    container_engine: "{{ kolla_container_engine }}"
    module_name: openstack.cloud.project_info
    module_args:
      auth: "{{ octavia_user_auth }}"
      cacert: "{{ openstack_cacert }}"
      endpoint_type: "{{ openstack_interface }}"
      region_name: "{{ openstack_region_name }}"
      name: "{{ octavia_service_auth_project }}"
  run_once: True
  delegate_to: "{{ groups['octavia-api'][0] }}"
  check_mode: false
  register: project_info

# NOTE(wuchunyang): ansible doesn't have a module to query security groups
# let's use os_security_group module instead.
- name: Get security groups for octavia
  become: true
  kolla_toolbox:
    container_engine: "{{ kolla_container_engine }}"
    module_name: openstack.cloud.security_group
    module_args:
      auth: "{{ octavia_user_auth }}"
      cacert: "{{ openstack_cacert }}"
      endpoint_type: "{{ openstack_interface }}"
      region_name: "{{ openstack_region_name }}"
      state: present
      name: "{{ item.name }}"
  loop: "{{ octavia_amp_security_groups.values() | list }}"
  loop_control:
    label: "{{ item.name }}"
  run_once: True
  delegate_to: "{{ groups['octavia-api'][0] }}"
  check_mode: false
  register: sec_grp_info

- name: Get loadbalancer management network
  become: true
  kolla_toolbox:
    container_engine: "{{ kolla_container_engine }}"
    module_name: openstack.cloud.networks_info
    module_args:
      auth: "{{ octavia_user_auth }}"
      cacert: "{{ openstack_cacert }}"
      endpoint_type: "{{ openstack_interface }}"
      region_name: "{{ openstack_region_name }}"
      name: "{{ octavia_amp_network['name'] }}"
  register: network_results
  run_once: True
  delegate_to: "{{ groups['octavia-api'][0] }}"
  check_mode: false

- name: Set octavia resources facts
  set_fact:
    network_info: "{{ network_results.networks | first }}"
    amphora_flavor_info: "{{ flavor_results.flavors | first }}"
