first draft for postgres
This commit is contained in:
parent
35dd9b5a04
commit
b4e5dbf548
1 changed files with 65 additions and 0 deletions
65
roles/postgre/tasks/main.yml
Normal file
65
roles/postgre/tasks/main.yml
Normal 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 }}"
|
||||
|
Loading…
Reference in a new issue