---

- name: install ceph
  apt:
    force_apt_get: true
    install_recommends: false
    name: "{{ ceph_packages }}"

- name: ceph config
  template:
    src: ceph.conf.j2
    dest: /etc/ceph/ceph.conf

- name: ceph keyring
  template:
    src: ceph.client.user.keyring.j2
    dest: /etc/ceph/ceph.client.{{ ceph_login }}.keyring
    mode: 0600

- name: check rbd image presence
  when: inventory_hostname == play_hosts[0]
  register: ceph_check_image
  changed_when: ceph_check_image.stdout != ceph_image_name
  command:
    cmd: rbd -n client.{{ ceph_login }} list {{ ceph_pool_name }}
  ignore_errors: yes

- name: create rbd image
  when:
    - ceph_check_image is changed
    - inventory_hostname == play_hosts[0]
  command:
    cmd: rbd -n client.{{ ceph_login }} create {{ ceph_pool_name }}/{{ ceph_image_name }} {{ ceph_parameters | join(' ') }}

- name: map rbd image to device
  command:
    cmd: rbd -n client.{{ ceph_login }} map {{ ceph_pool_name }}/{{ ceph_image_name }}
    creates: /dev/rbd0

- name: configure rbd map at boot
  notify: restart rbdmap
  lineinfile:
    path: /etc/ceph/rbdmap
    backup: true
    line: "{{ ceph_pool_name }}/{{ ceph_image_name }} id={{ ceph_login }},keyring=/etc/ceph/ceph.client.{{ ceph_login }}.keyring"

- name: enable rbdmap service
  systemd:
    name: rbdmap
    enabled: true
    state: started

- meta: flush_handlers

...