ansible/roles/postgresql/tasks/main.yml

45 lines
1.1 KiB
YAML

#!/usr/bin/ansible-playbook
# vim:ft=ansible:
---
- name: Set up PostgreSQL
block:
- name: Install PostgreSQL
apt:
name:
- libpq-dev
- postgresql
- postgresql-contrib
- python3-psycopg2
- name: Template out configs
template:
src: "{{ item }}"
dest: "/etc/postgresql/10/main/{{ item }}"
loop:
- postgresql.conf
- pg_hba.conf
notify: restart psql
- name: Start PostgreSQL
systemd:
name: postgresql
enabled: yes
state: started
- name: Configure DB
block:
- name: Create DB user
postgresql_user:
name: "{{ psql_ansible_user }}"
password: "{{ psql_ansible_password }}"
role_attr_flags: SUPERUSER
- name: Create maintenance DB
postgresql_db:
name: "{{ psql_ansible_user }}"
owner: "{{ psql_ansible_user }}"
become: yes
become_user: postgres
- name: Template out backup module
template:
src: backup.sh
dest: /opt/backups/modules/psql.sh
mode: "0600"
become: yes