---
- name: Create monitor initial keyring
  command: "ceph-authtool /var/lib/ceph/tmp/keyring.mon.{{ ansible_hostname }} --create-keyring --name=mon. --add-key={{ monitor_secret }} --cap mon 'allow *' creates=/var/lib/ceph/tmp/keyring.mon.{{ ansible_hostname }}"

- name: Set initial monitor key permissions
  file: >
    path=/var/lib/ceph/tmp/keyring.mon.{{ ansible_hostname }}
    mode=0600
    owner=root
    group=root

- name: Create monitor directory
  file: >
    path=/var/lib/ceph/mon/ceph-{{ ansible_hostname }}
    state=directory
    owner=root
    group=root
    mode=0644

- name: Ceph monitor mkfs
  command: "ceph-mon --mkfs -i {{ ansible_hostname }} --fsid {{ cluster_uuid.stdout }} --keyring /var/lib/ceph/tmp/keyring.mon.{{ ansible_hostname }} creates=/var/lib/ceph/mon/ceph-{{ ansible_hostname }}/keyring"

- name: Start and add that the monitor service to the init sequence
  service: >
    name=ceph
    state=started
    enabled=yes
    args=mon

---
- name: Create monitor secret
  shell: ceph-authtool --gen-print-key | tee /etc/ceph/ceph_monitor_secret.conf creates=/etc/ceph/ceph_monitor_secret.conf
  register: monitor_secret

- name: Read monitor secret if it already exists
  command: cat /etc/ceph/ceph_monitor_secret.conf removes=/etc/ceph/ceph_monitor_secret.conf
  register: monitor_secret

- name: Create monitor initial keyring
  command: "ceph-authtool /var/lib/ceph/tmp/keyring.mon.{{ ansible_hostname }} --create-keyring --name=mon. --add-key={{ monitor_secret.stdout }} --cap mon 'allow *' creates=/var/lib/ceph/tmp/keyring.mon.{{ ansible_hostname }}"

- name: Set initial monitor key permissions
  file: >
    path={{ item }}
    mode=0400
    owner=root
    group=root
  with_items:
    - /etc/ceph/ceph_monitor_secret.conf
    - /var/lib/ceph/tmp/keyring.mon.{{ ansible_hostname }}

- name: Create monitor directory
  file: >
    path=/var/lib/ceph/mon/ceph-{{ ansible_hostname }}
    state=directory
    owner=root
    group=root
    mode=0644

- name: Ceph monitor mkfs
  command: "ceph-mon --mkfs -i {{ ansible_hostname }} --fsid {{ cluster_uuid.stdout }} --keyring /var/lib/ceph/tmp/keyring.mon.{{ ansible_hostname }} creates=/var/lib/ceph/mon/ceph-{{ ansible_hostname }}/keyring"

- name: Start and add that the monitor service to the init sequence
  service: >
    name=ceph
    state=started
    enabled=yes
    args=mon

Fix autogen UUID and add auto gen monitor key
Fix autogen UUID and add auto gen monitor key

This fixes the UUID auto generation and introduces the monitor key auto
generation.

Signed-off-by: Sébastien Han <c944cdd58d18a32bd34d661eafe66112d96c6cc1@enovance.com>
