ansible/roles/postgre/tasks/main.yml

67 lines
1.6 KiB
YAML
Raw Normal View History

2021-07-27 04:01:49 +02:00
---
- name: Install postgre and usefull packages
apt:
update_cache: yes
name:
- acl # Don't ask me, required by postgresql_user
2021-07-27 04:01:49 +02:00
- 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 }} SET client_encoding TO 'utf8'"
loop: "{{ postgres_users | map(attribute='name') }}"
2021-07-27 04:01:49 +02:00
- name: Set encoding
become: true
become_user: postgres
postgresql_query:
query: "ALTER ROLE {{ item }} SET default_transaction_isolation TO 'read committed'"
when: item.read_committed | default(false)
loop: "{{ postgres_users | map(attribute='name') }}"
2021-07-27 04:01:49 +02:00
- name: Set timezone
become: true
become_user: postgres
postgresql_query:
query: "ALTER ROLE {{ item }} SET timezone TO 'CET'"
loop: "{{ postgres_users | map(attribute='name') }}"
2021-07-27 04:01:49 +02:00