---
- import_role:
    name: service-precheck
  vars:
    service_precheck_services: "{{ designate_services }}"
    service_name: "{{ project_name }}"

- name: Get container facts
  become: true
  kolla_container_facts:
    action: get_containers
    container_engine: "{{ kolla_container_engine }}"
    name:
      - designate_api
      - designate_backend_bind9
      - designate_mdns
  check_mode: false
  register: container_facts

- name: Checking free port for designate API
  wait_for:
    host: "{{ api_interface_address }}"
    port: "{{ designate_api_listen_port }}"
    connect_timeout: 1
    timeout: 1
    state: stopped
  when:
    - container_facts.containers['designate_api'] is not defined
    - inventory_hostname in groups['designate-api']

- name: Checking free port for designate mdns
  wait_for:
    host: "{{ 'dns' | kolla_address }}"
    port: "{{ designate_mdns_port }}"
    connect_timeout: 1
    timeout: 1
    state: stopped
  when:
    - container_facts.containers['designate_mdns'] is not defined
    - inventory_hostname in groups['designate-mdns']

- name: Checking free port for designate backend bind9 port
  wait_for:
    host: "{{ api_interface_address }}"
    port: "{{ designate_bind_port }}"
    connect_timeout: 1
    timeout: 1
    state: stopped
  when:
    - designate_backend == 'bind9'
    - container_facts.containers['designate_backend_bind9'] is not defined
    - inventory_hostname in groups['designate-backend-bind9']

- name: Checking free port for designate backend rndc port
  wait_for:
    host: "{{ api_interface_address }}"
    port: "{{ designate_rndc_port }}"
    connect_timeout: 1
    timeout: 1
    state: stopped
  when:
    - designate_backend == 'bind9'
    - container_facts.containers['designate_backend_bind9'] is not defined
    - inventory_hostname in groups['designate-backend-bind9']
