---
- 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
  when: ( ( inventory_hostname in groups['compute'] or inventory_hostname in groups['cinder-volume'] ) and enable_cinder | bool and enable_cinder_backend_iscsi | bool )
         or ( inventory_hostname in groups['ironic-conductor'] and enable_ironic | bool )
  with_items:
    - "iscsid"

- name: Copying over config.json files for services
  template:
    src: "{{ item }}.json.j2"
    dest: "{{ node_config_directory }}/{{ item }}/config.json"
    mode: "0660"
  become: true
  when: ( ( inventory_hostname in groups['compute'] or inventory_hostname in groups['cinder-volume'] ) and enable_cinder | bool and enable_cinder_backend_iscsi | bool )
         or ( inventory_hostname in groups['ironic-conductor'] and enable_ironic | bool )
  with_items:
    - "iscsid"

- 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
  when:
    - enable_cinder_backend_lvm | bool
    - inventory_hostname in groups['tgtd']
  with_items:
    - "tgtd"

- name: Copying over config.json files for services
  template:
    src: "{{ item }}.json.j2"
    dest: "{{ node_config_directory }}/{{ item }}/config.json"
    mode: "0660"
  become: true
  when:
    - enable_cinder_backend_lvm | bool
    - inventory_hostname in groups['tgtd']
  with_items:
    - "tgtd"
