๐Ÿ“— Ansible playbooks and roles for building an idempotent, interconnected and scalable infrastructure
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.

44 lines
1.1 KiB

2 years ago
- name: check if system table already exists
include_role:
name: postgres
apply:
delegate_to: "{{ inventory_hostname if database_self_hosted else services.db.hostname }}"
vars:
function: run_query
query:
database: "{{ database_name }}"
text: "SELECT to_regclass('public.system');"
- name: set db_is_empty fact
set_fact:
db_is_empty: "{{ (query_result is defined) and (query_result[0].to_regclass is none) }}"
- block:
- name: slurp script from roundcube to ansible
slurp:
src: "{{ roundcube_dir }}/SQL/postgres.initial.sql"
register: fetched
- name: run script
include_role:
name: postgres
apply:
delegate_to: "{{ inventory_hostname if database_self_hosted else services.db.hostname }}"
vars:
function: run_script
script:
database: "{{ database_name }}"
text: "{{ fetched.content | b64decode }}"
refresh_privs: yes
as_single_query: yes
user: "{{ database_user }}"
when: db_is_empty == true
- name: unset db_empty fact
set_fact:
db_is_empty: "{{ None }}"