2021-03-10 12:01:32 +01:00
|
|
|
---
|
|
|
|
- name: Install postgresql
|
|
|
|
apt:
|
|
|
|
update_cache: true
|
|
|
|
name: postgresql
|
|
|
|
state: present
|
|
|
|
register: apt_result
|
2021-03-10 12:08:05 +01:00
|
|
|
retries: 3
|
|
|
|
until: apt_result is succeeded
|
2021-03-10 12:01:32 +01:00
|
|
|
|
|
|
|
- name: Ensure main postgresql directory exists
|
|
|
|
file:
|
|
|
|
path: /etc/postgresql/{{ postgresql.version }}/main/
|
|
|
|
state: directory
|
|
|
|
owner: postgres
|
|
|
|
group: postgres
|
|
|
|
mode: 0755
|
2021-03-10 12:10:06 +01:00
|
|
|
recurse: true
|
2021-03-10 12:01:32 +01:00
|
|
|
|
|
|
|
- name: Ensure configuration directory exists
|
|
|
|
file:
|
|
|
|
path: /etc/postgresql/{{ postgresql.version }}/main/conf.d
|
|
|
|
state: directory
|
|
|
|
owner: postgres
|
|
|
|
group: postgres
|
|
|
|
mode: 0755
|
2021-03-10 12:11:02 +01:00
|
|
|
|
2021-03-10 12:01:32 +01:00
|
|
|
- name: Configuration of postgresql {{ postgresql.version }}
|
|
|
|
template:
|
|
|
|
src: postgresql/{{ item }}.j2
|
|
|
|
dest: /etc/postgresql/{{ postgresql.version }}/main/{{ item }}
|
|
|
|
mode: 0640
|
|
|
|
owner: postgres
|
|
|
|
group: postgres
|
|
|
|
loop:
|
|
|
|
- pg_hba.conf
|
|
|
|
- postgresql.conf
|
|
|
|
notify:
|
|
|
|
- restart postgresql
|
2021-03-10 13:23:52 +01:00
|
|
|
|
|
|
|
- name: Create databases
|
|
|
|
postgresql_db:
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
loop: "{{ postgresql_databases }}"
|
|
|
|
|
|
|
|
- name: Create users
|
|
|
|
postgresql_user:
|
|
|
|
db: "{{ item.database }}"
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
password: "{{ item.password }}"
|
|
|
|
priv: "{{ item.priv }}"
|
|
|
|
loop: "{{ postgresql_users }}"
|
|
|
|
...
|