---
- name: Cleaning up temp file on localhost
  local_action: file path=/tmp/kolla_ceph_cluster state=absent
  changed_when: False
  always_run: True
  run_once: True

- name: Creating temp file on localhost
  local_action: copy content=None dest=/tmp/kolla_ceph_cluster mode=0600
  changed_when: False
  always_run: True
  run_once: True

# TODO(SamYaple): Improve failed_when check
- name: Checking if a previous cluster exists
  command: docker exec ceph_mon_data stat /etc/ceph/ceph.monmap
  register: exists
  changed_when: False
  failed_when: False
  always_run: True

- name: Writing hostname of host with existing cluster files to temp file
  local_action: copy content={{ ansible_hostname }} dest=/tmp/kolla_ceph_cluster mode=0600
  changed_when: False
  always_run: True
  when: exists.rc == 0

- name: Registering host from temp file
  set_fact:
    delegate_host: "{{ lookup('file', '/tmp/kolla_ceph_cluster') }}"

- name: Cleaning up temp file on localhost
  local_action: file path=/tmp/kolla_ceph_cluster state=absent
  changed_when: False
  always_run: True
  run_once: True

- include: generate_cluster.yml
  when: delegate_host == 'None' and inventory_hostname == groups['ceph-mon'][0]

---
- name: Cleaning up temp file on localhost
  local_action: file path=/tmp/kolla_ceph_cluster state=absent
  changed_when: False
  always_run: True
  run_once: True

- name: Creating temp file on localhost
  local_action: copy content=None dest=/tmp/kolla_ceph_cluster mode=0600
  changed_when: False
  always_run: True
  run_once: True

- name: Creating ceph_mon_conifg volume
  kolla_docker:
    action: "create_volume"
    common_options: "{{ docker_common_options }}"
    name: "ceph_mon_config"
  register: ceph_mon_config_volume

- name: Writing hostname of host with existing cluster files to temp file
  local_action: copy content={{ ansible_hostname }} dest=/tmp/kolla_ceph_cluster mode=0600
  changed_when: False
  always_run: True
  when: not ceph_mon_config_volume.changed

- name: Registering host from temp file
  set_fact:
    delegate_host: "{{ lookup('file', '/tmp/kolla_ceph_cluster') }}"

- name: Cleaning up temp file on localhost
  local_action: file path=/tmp/kolla_ceph_cluster state=absent
  changed_when: False
  always_run: True
  run_once: True

- include: generate_cluster.yml
  when: delegate_host == 'None' and inventory_hostname == groups['ceph-mon'][0]

Fix ceph-mon existing cluster detection logic
Fix ceph-mon existing cluster detection logic

After moving from data container to named volumes, ceph monmap detection
is broken. This change fix the logic by leverage kolla_docker's
idempotency creating a named volume.

Change-Id: Iabc2e2fe5f526e1a6fc2e1b1158d1702aaf4bdf9
Related-Bug: #1533368
