---
- name: Check if all rabbit hostnames are resolvable
  command: "getent ahostsv4 {{ hostvars[item]['ansible_hostname'] }}"
  changed_when: false
  register: rabbitmq_hostnames
  with_items: groups['rabbitmq']

- fail: msg="Hostname has to resolve to IP address of api_interface"
  with_items: rabbitmq_hostnames.results
  when: "{% set ip=item.stdout.split(' ')[0] %}'{{ hostvars[item['item']]['ansible_' + hostvars[item['item']]['api_interface']]['ipv4']['address'] }}' != '{{ ip }}'"

- name: Creating rabbitmq volume
  kolla_docker:
    action: "create_volume"
    common_options: "{{ docker_common_options }}"
    name: "rabbitmq"
  register: rabbitmq_volume

- name: Running RabbitMQ bootstrap container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    detach: False
    environment:
      KOLLA_BOOTSTRAP:
      KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
      RABBITMQ_CLUSTER_COOKIE: "{{ rabbitmq_cluster_cookie }}"
    image: "{{ rabbitmq_image_full }}"
    labels:
      BOOTSTRAP:
    name: "rabbitmq_bootstrap"
    restart_policy: "never"
    volumes:
      - "{{ node_config_directory }}/rabbitmq/:{{ container_config_directory }}/:ro"
      - "rabbitmq:/var/lib/rabbitmq/"
  when: rabbitmq_volume | changed

---
- name: Check if all rabbit hostnames are resolvable
  command: "getent ahostsv4 {{ hostvars[item]['ansible_hostname'] }}"
  changed_when: false
  register: rabbitmq_hostnames
  with_items: groups['rabbitmq']

- fail: msg="Hostname has to resolve to IP address of api_interface"
  with_items: rabbitmq_hostnames.results
  when: "'{{ hostvars[item['item']]['ansible_' + hostvars[item['item']]['api_interface']]['ipv4']['address'] }}' not in '{{ item.stdout }}'"

- name: Creating rabbitmq volume
  kolla_docker:
    action: "create_volume"
    common_options: "{{ docker_common_options }}"
    name: "rabbitmq"
  register: rabbitmq_volume

- name: Running RabbitMQ bootstrap container
  kolla_docker:
    action: "start_container"
    common_options: "{{ docker_common_options }}"
    detach: False
    environment:
      KOLLA_BOOTSTRAP:
      KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
      RABBITMQ_CLUSTER_COOKIE: "{{ rabbitmq_cluster_cookie }}"
    image: "{{ rabbitmq_image_full }}"
    labels:
      BOOTSTRAP:
    name: "rabbitmq_bootstrap"
    restart_policy: "never"
    volumes:
      - "{{ node_config_directory }}/rabbitmq/:{{ container_config_directory }}/:ro"
      - "rabbitmq:/var/lib/rabbitmq/"
  when: rabbitmq_volume | changed

Fix IP resolve check for RabbitMQ on AIO
Fix IP resolve check for RabbitMQ on AIO

On AIO installation we cannot assume that the public IP address
will be the first entry in "getent ahostsv4" result, because
it may be also a localhost address. To make this check positive
in AIO, we should look for the public IP in the whole output.

Change-Id: I1da7b95d7f00c7f87ff68ead46bf55fdea812599
Closes-Bug: 1564564
(cherry picked from commit 5aa2dcce3089d08a46175513fecb55ce91004769)
