---

- name: Run the postgresql-setup initdb command
  ansible.builtin.shell: postgresql-setup initdb
  args:
    executable: /bin/bash
  ignore_errors: True
  tags:
    - db-configure

# db needs to be running at this step
- name: Ensuring postgresql server is started
  ansible.builtin.service:
    name: postgresql
    state: reloaded
    enabled: True
  tags:
    - zabbix-services


- name: Connect to acme database, create django user, and grant access to database and products table
  postgresql_user:
    name: "{{ zabbix_db_user }}"
    password: "{{ zabbix_db_pass }}"
  become: true
  become_user: postgres
  tags:
    - db-configure

- name: Configure the zabbix db
  ansible.builtin.shell: "sudo -u postgres createdb -O {{ zabbix_db_user }} {{ zabbix_db_name }}"
  ignore_errors: True
  tags:
    - db-configure

- name: Import the zabbix db schemas
  ansible.builtin.shell: "zcat /usr/share/zabbix-sql-scripts/postgresql/server.sql.gz | sudo -u zabbix psql zabbix"
  args:
    executable: /bin/bash
  ignore_errors: True
  tags:
    - db-configure

