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.
61 lines
1.3 KiB
61 lines
1.3 KiB
2 years ago
|
- block:
|
||
|
- name: check if system table is missing
|
||
|
community.postgresql.postgresql_query:
|
||
|
db: "{{ database_name | mandatory }}"
|
||
|
query: SELECT to_regclass('public.system');
|
||
|
register: db_result
|
||
|
changed_when: false
|
||
|
|
||
|
- name: set db_is_empty fact
|
||
|
set_fact:
|
||
|
db_is_empty: "{{ (db_result.query_result is defined) and (db_result.query_result[0].to_regclass is none) }}"
|
||
|
delegate_to: postgres
|
||
|
|
||
|
|
||
|
- name: fetch script from mail to ansible
|
||
|
fetch:
|
||
|
src: "{{ mail_dir }}/SQL/postgres.initial.sql"
|
||
|
dest: /tmp/
|
||
|
flat: yes
|
||
|
register: fetched
|
||
|
when: db_is_empty
|
||
|
|
||
|
|
||
|
- block:
|
||
|
- name: create temporary file on postgres for holding the script
|
||
|
tempfile:
|
||
|
state: file
|
||
|
register: tf
|
||
|
|
||
|
- name: upload script
|
||
|
copy:
|
||
|
src: "{{ fetched.dest }}"
|
||
|
dest: "{{ tf.path }}"
|
||
|
force: yes
|
||
|
|
||
|
- name: execute script
|
||
|
community.postgresql.postgresql_query:
|
||
|
db: "{{ database_name | mandatory }}"
|
||
|
path_to_script: "{{ tf.path }}"
|
||
|
as_single_query: no
|
||
|
|
||
|
- name: remove temp script
|
||
|
file:
|
||
|
path: "{{ tf.path }}"
|
||
|
state: absent
|
||
|
|
||
|
when: db_is_empty
|
||
|
delegate_to: postgres
|
||
|
|
||
|
|
||
|
- name: remove fetched script
|
||
|
file:
|
||
|
path: "{{ fetched.dest }}"
|
||
|
state: absent
|
||
|
when: db_is_empty
|
||
|
|
||
|
|
||
|
- name: update db privileges
|
||
|
include_tasks: tasks/psql_grant_privs.yml
|
||
|
when: db_is_empty
|