# This file sets the correct ownership rights for Moodle volumes

- name: Set ownership and permissions on Moodle directories
  vars:
    moodle_dirs:
      - "{{ bitnami_code_dir }}"
      - "{{ bitnami_data_dir }}"
  block:
    - name: Ensure ownership is correct
      command: "docker exec --user root {{ moodle_container }} chown -R {{ bitnami_user_group }} {{ item }}"
      loop: "{{ moodle_dirs }}"

    - name: Set directory permissions (770)
      command: "docker exec --user root {{ moodle_container }} find {{ item }} -type d -exec chmod 770 {} \\;"
      loop: "{{ moodle_dirs }}"

    - name: Set file permissions (660)
      command: "docker exec --user root {{ moodle_container }} find {{ item }} -type f -exec chmod 660 {} \\;"
      loop: "{{ moodle_dirs }}"
