You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.7 KiB
55 lines
1.7 KiB
- name: create postgres user and database
|
|
include_role:
|
|
name: postgres
|
|
apply:
|
|
delegate_to: "{{ mail_server.db_server_hostname }}"
|
|
vars:
|
|
function: add_database
|
|
database:
|
|
name: "{{ mail_server.db_name }}"
|
|
user: "{{ mail_server.db_user }}"
|
|
pass: "{{ mail_server.db_pass }}"
|
|
addresses: "{{ [
|
|
(hostvars[mail_server.mta_hostname]['ansible_host'] if mail_server.mta_hostname is defined else ''),
|
|
(hostvars[mail_server.mua_hostname]['ansible_host'] if mail_server.mua_hostname is defined else ''),
|
|
(hostvars[mail_server.rspamd_hostname]['ansible_host'] if mail_server.rspamd_hostname is defined else '')
|
|
] | select() | list }}"
|
|
|
|
|
|
- name: check if users table already exists
|
|
include_role:
|
|
name: postgres
|
|
apply:
|
|
delegate_to: "{{ mail_server.db_server_hostname }}"
|
|
vars:
|
|
function: run_query
|
|
query:
|
|
database: "{{ mail_server.db_name }}"
|
|
text: "SELECT to_regclass('public.users');"
|
|
|
|
|
|
- name: build database schema
|
|
include_role:
|
|
name: postgres
|
|
apply:
|
|
delegate_to: "{{ mail_server.db_server_hostname }}"
|
|
vars:
|
|
function: run_query
|
|
query:
|
|
database: "{{ mail_server.db_name }}"
|
|
text: "{{ lookup('file', './files/schema.sql') }}"
|
|
user: "{{ mail_server.db_user }}"
|
|
refresh_privs: yes
|
|
when: (query_result is defined) and (query_result[0].to_regclass is none)
|
|
|
|
|
|
- name: create database entries
|
|
include_role:
|
|
name: postgres
|
|
apply:
|
|
delegate_to: "{{ mail_server.db_server_hostname }}"
|
|
vars:
|
|
function: run_query
|
|
query:
|
|
database: "{{ mail_server.db_name }}"
|
|
text: "{{ lookup('template', './templates/sql.j2') }}"
|
|
|