--- - name: Install postgresql ansible.builtin.package: name: postgresql state: present - name: Create pgsql directory ansible.builtin.file: path: /srv/postgresql owner: postgres group: postgres state: directory mode: 0700 - name: Populate postgresql directory ansible.builtin.command: cmd: "/usr/lib/postgresql/{{ pg_version }}/bin/initdb -E UTF-8 /srv/postgresql/" creates: /srv/postgresql/PG_VERSION become: true become_user: postgres notify: Restart postgres - name: Replace main conffile ansible.builtin.copy: src: files/postgresql.conf dest: "/etc/postgresql/{{ pg_version }}/main/postgresql.conf" mode: 0644 notify: Restart postgres - name: Replace pg_hba file ansible.builtin.copy: src: files/pg_hba.conf dest: "/etc/postgresql/{{ pg_version }}/main/pg_hba.conf" mode: 0640 notify: Restart postgres - name: Create backup dir ansible.builtin.file: path: /srv/backup/pgsql owner: postgres group: postgres state: directory mode: 0755 - name: Backup pg databases ansible.builtin.cron: user: postgres minute: "0" hour: "4" name: PG Backup job: "/usr/bin/pg_dumpall | gzip -c > /srv/backup/pgsql/all.dbs.gz"