automation/deployer/roles/build/tasks/postgres.yml

39 lines
1.2 KiB
YAML
Raw Normal View History

2020-06-01 06:21:27 +00:00
---
# Needs variables:
# - site: dict describing the site install (cf group_vars/all/vars.yml)
- name: "Create database {{ site.postgres_database }} if inexistent"
postgresql_db:
name: "{{ site.postgres_database }}"
owner: "{{ site.postgres_username }}"
encoding: "UTF-8"
lc_collate: "C"
lc_ctype: "C"
template: template0
state: present
become: yes
become_user: postgres
2020-06-01 06:21:27 +00:00
- name: "Add database user {{ site.postgres_username }} and grant all privileges on {{ site.postgres_database }}"
postgresql_user:
# Credentials of the new db user
name: "{{ site.postgres_username }}"
password: "{{ site.postgres_password }}"
db: "{{ site.postgres_database }}"
priv: ALL
# host: "{{ site.subnet_site_ip }}"
become: yes
become_user: postgres
- name: "Authorize {{ site.subnet_site_ip }} to login to Postgres as user {{ site.postgres_username }}"
postgresql_pg_hba:
dest: "{{ postgres.pg_hba_path }}"
contype: host
users: "{{ site.postgres_username }}"
source: "{{ site.subnet_site_ip }}"
databases: "{{ site.postgres_database }}"
method: md5
state: present
become: yes
become_user: postgres
notify: Restart postgres