---
# Variable configuration.
- name: Include Variables
  ansible.builtin.include_tasks: variables.yml
- name: ArchLinux-setup
  ansible.builtin.include_tasks: setup-Archlinux.yml
  when: ansible_facts.os_family == 'Archlinux'

- name: Debian-setup
  ansible.builtin.include_tasks: setup-Debian.yml
  when: ansible_facts.os_family == 'Debian'

- name: RHEL-Setup
  ansible.builtin.include_tasks: setup-RedHat.yml
  when: ansible_facts.os_family == 'RedHat'

- name: Enable TimeScaleDB
  ansible.builtin.include_tasks: timescaledb.yml
  when: timescaledb_enabled is true

- name: PostgreSQL Initialization
  ansible.builtin.include_tasks: initialize.yml
- name: PostgreSQL Configuration
  ansible.builtin.include_tasks: configure.yml

- name: Ensure PostgreSQL is started and enabled on boot.
  ansible.builtin.service:
    name: "{{ postgresql_daemon }}"
    state: "{{ postgresql_service_state }}"
    enabled: "{{ postgresql_service_enabled }}"

# Configure PostgreSQL.
- name: Create PostgreSQL users
  ansible.builtin.import_tasks: users.yml
- name: Create PostgreSQL databases
  ansible.builtin.import_tasks: databases.yml
- name: Set PostgreSQL user properties
  ansible.builtin.import_tasks: users_props.yml
