---
- name: Ensuring config directories exist
  file:
    path: "{{ node_config_directory }}/{{ item }}"
    state: "directory"
    owner: "{{ config_owner_user }}"
    group: "{{ config_owner_group }}"
    mode: "0770"
  become: true
  with_items:
    - "ceph-mon"
    - "ceph-osd"
    - "ceph-rgw"
    - "ceph-mgr"
    - "ceph-mds"
    - "ceph-nfs"

- name: Copying over config.json files for services
  template:
    src: "{{ item.name }}.json.j2"
    dest: "{{ node_config_directory }}/{{ item.name }}/config.json"
    mode: "0660"
  become: true
  when:
    - inventory_hostname in groups[item.group]
  with_items:
    - name: "ceph-mon"
      group: ceph-mon
    - name: "ceph-osd"
      group: ceph-osd
    - name: "ceph-rgw"
      group: ceph-rgw
    - name: "ceph-mgr"
      group: ceph-mgr
    - name: "ceph-mds"
      group: ceph-mds
    - name: "ceph-nfs"
      group: ceph-nfs

- name: Copying over ceph.conf
  vars:
    service_name: "{{ item }}"
  merge_configs:
    sources:
      - "{{ role_path }}/templates/ceph.conf.j2"
      - "{{ node_custom_config }}/ceph.conf"
      - "{{ node_custom_config }}/ceph/{{ inventory_hostname }}/ceph.conf"
    dest: "{{ node_config_directory }}/{{ item }}/ceph.conf"
    mode: "0660"
  become: true
  with_items:
    - "ceph-mon"
    - "ceph-osd"
    - "ceph-rgw"
    - "ceph-mgr"
    - "ceph-mds"
    - "ceph-nfs"
