first draft for postgres

This commit is contained in:
histausse 2021-07-27 04:01:49 +02:00
parent 35dd9b5a04
commit b4e5dbf548
Signed by: histausse
GPG key ID: 67486F107F62E9E9

View file

@ -0,0 +1,65 @@
---
- name: Install postgre and usefull packages
apt:
update_cache: yes
name:
- postgresql
- postgresql-contrib
- libpq-dev
- python3-dev
- python3-psycopg2
- libpq5
state: latest
register: apt_result
retries: 3
until: apt_result is succeeded
- name: Enable and start PostgreSQL
systemd:
name: postgresql.service
state: started
enabled: yes
- name: Create users
become: true
become_user: postgres
postgresql_user:
name: "{{ item.name }}"
encrypted: yes
password: "{{ item.password }}"
loop: "{{ postgres_users }}"
- name: Create databases
become: true
become_user: postgres
postgresql_db:
name: "{{ item.name }}"
encoding: UTF-8
owner: "{{ item.owner | default(omit) }}"
lc_collate: "{{ item.local | default(omit) }}"
lc_ctype: "{{ item.local | default(omit) }}"
template: "{{ item.template | default(omit) }}"
loop: "{{ databases }}"
- name: Set encoding
become: true
become_user: postgres
postgresql_query:
query: "ALTER ROLE {{ item.name }} SET client_encoding TO 'utf8'"
loop: "{{ databases }}"
- name: Set encoding
become: true
become_user: postgres
postgresql_query:
query: "ALTER ROLE {{ item.name }} SET default_transaction_isolation TO 'read committed'"
when: "{{ item.read_committed | default(false) }}"
loop: "{{ databases }}"
- name: Set timezone
become: true
become_user: postgres
postgresql_query:
query: "ALTER ROLE {{ item.name }} SET timezone TO 'CET'"
loop: "{{ databases }}"