---
- name: Ensuring gnocchi service ceph config subdir exists
  file:
    path: "{{ node_config_directory }}/{{ item.key }}/ceph"
    state: "directory"
    owner: "{{ config_owner_user }}"
    group: "{{ config_owner_group }}"
    mode: "0770"
  become: true
  with_dict: "{{ gnocchi_services }}"
  when:
    - inventory_hostname in groups[item.value.group]
    - item.value.enabled | bool

- name: Copy over ceph config for Gnocchi
  merge_configs:
    sources:
      - "{{ node_custom_config }}/gnocchi/{{ gnocchi_ceph_cluster }}.conf"
      - "{{ node_custom_config }}/gnocchi/{{ item.key }}/{{ gnocchi_ceph_cluster }}.conf"
    dest: "{{ node_config_directory }}/{{ item.key }}/ceph/{{ gnocchi_ceph_cluster }}.conf"
    mode: "0660"
  become: true
  when:
    - inventory_hostname in groups[item.value.group]
    - item.value.enabled | bool
  with_dict: "{{ gnocchi_services }}"
  notify:
    - Restart {{ item.key }} container

- name: Copy over ceph Gnocchi keyrings
  template:
    src: "{{ node_custom_config }}/gnocchi/{{ gnocchi_ceph_cluster }}.{{ ceph_gnocchi_keyring }}"
    dest: "{{ node_config_directory }}/{{ item.key }}/ceph/{{ gnocchi_ceph_cluster }}.{{ ceph_gnocchi_keyring }}"
    mode: "0660"
  become: true
  with_dict: "{{ gnocchi_services }}"
  when:
    - inventory_hostname in groups[item.value.group]
    - item.value.enabled | bool
  notify:
    - Restart {{ item.key }} container

- name: Ensuring config directory has correct owner and permission
  become: true
  file:
    path: "{{ node_config_directory }}/{{ item.key }}"
    recurse: yes
    owner: "{{ config_owner_user }}"
    group: "{{ config_owner_group }}"
  when:
    - inventory_hostname in groups[item.value.group]
    - item.value.enabled | bool
  with_dict: "{{ gnocchi_services }}"
