# SPDX-License-Identifier: MIT
---
- name: >-
    Ensure the directory and permissions {{ __mssql_storage_path }}
  file:
    path: "{{ __mssql_storage_path }}"
    state: directory
    owner: mssql
    group: mssql
    mode: "{{ __mssql_storage_mode }}"

- name: Append facts for the selinux role
  vars:
    selinux_fcontext:
      - target: "{{ __mssql_storage_path }}"
        setype: "{{ 'mssql_db_t' if __mssql_storage_setting == 'defaultlogdir'
          else 'mssql_var_t' }}"
        ftype: d
        state: present
    selinux_restore_dir:
      - "{{ __mssql_storage_path }}"
  set_fact:
    selinux_fcontexts: "{{
      (selinux_fcontexts | default([])) + selinux_fcontext }}"
    selinux_restore_dirs: "{{
      (selinux_restore_dirs | default([])) + selinux_restore_dir }}"
  when:
    - mssql_manage_selinux | bool
    - mssql_run_selinux_confined | bool

- name: Configure the setting {{ __mssql_storage_setting }}
  include_tasks: mssql_conf_setting.yml
  vars:
    __mssql_conf_setting: filelocation {{ __mssql_storage_setting }}
    __mssql_conf_setting_value: "{{ __mssql_storage_path }}"
