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

- include_tasks: copy-certs.yml
  when:
    - kolla_copy_ca_into_containers | bool or skyline_enable_tls_backend | bool

- name: Copying over skyline.yaml files for services
  template:
    src: "skyline.yaml.j2"
    dest: "{{ node_config_directory }}/{{ item.key }}/skyline.yaml"
    mode: "0660"
  become: true
  when:
    - inventory_hostname in groups[item.value.group]
    - item.value.enabled | bool
  with_dict: "{{ skyline_services }}"
  notify:
    - "Restart {{ item.key }} container"

- name: Copying over gunicorn.py files for services
  template:
    src: "gunicorn.py.j2"
    dest: "{{ node_config_directory }}/{{ item.key }}/gunicorn.py"
    mode: "0660"
  become: true
  when:
    - inventory_hostname in groups['skyline-apiserver']
    - item.value.enabled | bool
  with_dict: "{{ skyline_services }}"
  notify:
    - "Restart {{ item.key }} container"

- name: Copying over nginx.conf files for services
  template:
    src: "nginx.conf.j2"
    dest: "{{ node_config_directory }}/{{ item.key }}/nginx.conf"
    mode: "0660"
  become: true
  when:
    - inventory_hostname in groups['skyline-console']
    - item.value.enabled | bool
  with_dict: "{{ skyline_services }}"
  notify:
    - "Restart {{ item.key }} container"

- name: Copying over config.json files for services
  template:
    src: "{{ item.key }}.json.j2"
    dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
    mode: "0660"
  become: true
  when:
    - inventory_hostname in groups[item.value.group]
    - item.value.enabled | bool
  with_dict: "{{ skyline_services }}"
  notify:
    - "Restart {{ item.key }} container"
