---
# Variable configuration.
-
  name: Include OS-specific variables (Debian).
  ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
  when: ansible_os_family == 'Debian'

-
  name: Include OS-specific variables (RedHat).
  ansible.builtin.include_vars: "{{ ansible_os_family }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
  when:
    - ansible_os_family == 'RedHat'
    - ansible_distribution != 'Fedora'
    - ansible_distribution != 'Amazon'

-
  name: Include OS-specific variables (Amazon).
  ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
  when: ansible_distribution == 'Amazon'

-
  name: Include OS-specific variables (Fedora).
  ansible.builtin.include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
  when: ansible_distribution == 'Fedora'

-
  name: Define postgresql_packages.
  ansible.builtin.set_fact:
    postgresql_packages: "{{ __postgresql_packages | list }}"
  when: postgresql_packages is not defined

-
  name: Define postgresql_version.
  ansible.builtin.set_fact:
    postgresql_version: "{{ __postgresql_version }}"
  when: postgresql_version is not defined

-
  name: Define postgresql_daemon.
  ansible.builtin.set_fact:
    postgresql_daemon: "{{ __postgresql_daemon }}"
  when: postgresql_daemon is not defined

-
  name: Define postgresql_data_dir.
  ansible.builtin.set_fact:
    postgresql_data_dir: "{{ __postgresql_data_dir }}"
  when: postgresql_data_dir is not defined

-
  name: Define postgresql_bin_path.
  ansible.builtin.set_fact:
    postgresql_bin_path: "{{ __postgresql_bin_path }}"
  when: postgresql_bin_path is not defined

-
  name: Define postgresql_config_path.
  ansible.builtin.set_fact:
    postgresql_config_path: "{{ __postgresql_config_path }}"
  when: postgresql_config_path is not defined

-
  name: Define postgresql_unix_socket_directories_mode.
  ansible.builtin.set_fact:
    postgresql_unix_socket_directories_mode: >-
      {{ __postgresql_unix_socket_directories_mode | default('02775') }}
  when: postgresql_unix_socket_directories_mode is not defined

-
  name: Define postgresql_log_dir.
  ansible.builtin.set_fact:
    # postgresql_global_config_options is an array but its keys are unique, so it can be converted to dict,
    # to easily get the value under the 'log_directory' key
    postgresql_log_dir: "{{ (postgresql_global_config_options | items2dict(key_name='option', value_name='value')).log_directory }}"

-
  name: Define postgresql_effective_log_dir, if postgresql_log_dir is absolute
  ansible.builtin.set_fact:
    postgresql_effective_log_dir: '{{ postgresql_log_dir }}'
  when: postgresql_log_dir is match("/")

-
  name: Define postgresql_effective_log_dir, if postgresql_log_dir is relative
  ansible.builtin.set_fact:
    postgresql_effective_log_dir: '{{ postgresql_data_dir }}/{{ postgresql_log_dir }}'
  when: postgresql_log_dir is not match("/")
