---
# Directory Setup Role
# Creates necessary directories for Docker services

- name: Create base docker directory
  ansible.builtin.file:
    path: "{{ docker_data_path }}"
    state: directory
    mode: '0755'
  when: create_base_dir | default(true)

- name: Create service directories
  ansible.builtin.file:
    path: "{{ docker_data_path }}/{{ item.name }}"
    state: directory
    mode: "{{ item.mode | default('0755') }}"
    owner: "{{ item.owner | default(omit) }}"
    group: "{{ item.group | default(omit) }}"
  loop: "{{ service_directories | default([]) }}"
  when: service_directories is defined

- name: Create nested service directories
  ansible.builtin.file:
    path: "{{ docker_data_path }}/{{ item.0.name }}/{{ item.1 }}"
    state: directory
    mode: "{{ item.0.mode | default('0755') }}"
    owner: "{{ item.0.owner | default(omit) }}"
    group: "{{ item.0.group | default(omit) }}"
  loop: "{{ service_directories | default([]) | subelements('subdirs', skip_missing=True) }}"
  when: service_directories is defined
