---
- name: Starting mariadb container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    image: "{{ mariadb_image_full }}"
    name: "mariadb"
    volumes:
      - "{{ node_config_directory }}/mariadb/:{{ container_config_directory }}/:ro"
      - "/etc/localtime:/etc/localtime:ro"
      - "mariadb:/var/lib/mysql"
      - "kolla_logs:/var/log/kolla/"
  when: delegate_host != 'None' or
        ( groups['mariadb'] | length ) == 1 or
        ( delegate_host == 'None' and mariadb_recover_inventory_name is not defined and inventory_hostname != groups['mariadb'][0] ) or
        ( delegate_host == 'None' and mariadb_recover_inventory_name is defined and inventory_hostname != mariadb_recover_inventory_name )


# TODO(jeffrey4l), remove the task check when the wair_for bug is fixed
# https://github.com/ansible/ansible-modules-core/issues/2788
- name: Waiting for MariaDB service to be ready
  wait_for:
    host: "{{ api_interface_address }}"
    port: "{{ mariadb_port }}"
    connect_timeout: 1
    timeout: 60
    search_regex: "MariaDB"
  register: check_mariadb_port
  until: check_mariadb_port | success
  retries: 10
  delay: 6