63 lines
1.4 KiB
YAML
63 lines
1.4 KiB
YAML
---
|
|
- name: Install postgresql and psycopg2
|
|
apt:
|
|
update_cache: true
|
|
pkg:
|
|
- postgresql
|
|
- python3-psycopg2
|
|
state: present
|
|
register: apt_result
|
|
retries: 3
|
|
until: apt_result is succeeded
|
|
|
|
- name: Ensure main postgresql directory exists
|
|
file:
|
|
path: /etc/postgresql/{{ postgresql.version }}/main/
|
|
state: directory
|
|
owner: postgres
|
|
group: postgres
|
|
mode: 0755
|
|
|
|
- name: Ensure configuration directory exists
|
|
file:
|
|
path: /etc/postgresql/{{ postgresql.version }}/main/conf.d
|
|
state: directory
|
|
owner: postgres
|
|
group: postgres
|
|
mode: 0755
|
|
|
|
- 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
|
|
|
|
- name: Create databases
|
|
become: true
|
|
become_user: postgres
|
|
postgresql_db:
|
|
name: "{{ item }}"
|
|
encoding: UTF-8
|
|
lc_collate: en_US.UTF-8
|
|
lc_ctype: en_US.UTF-8
|
|
template: template0
|
|
loop: "{{ postgresql_databases }}"
|
|
|
|
- name: Create users
|
|
become: true
|
|
become_user: postgres
|
|
postgresql_user:
|
|
db: "{{ item.database }}"
|
|
name: "{{ item.name }}"
|
|
password: "{{ item.password }}"
|
|
priv: "{{ item.priv }}"
|
|
no_log: true
|
|
loop: "{{ postgresql_users }}"
|
|
...
|