parent
180fac8048
commit
a297c0401d
|
@ -1,4 +1,16 @@
|
||||||
---
|
---
|
||||||
|
- name: Collect PostgreSQL db_names
|
||||||
|
postgresql_query:
|
||||||
|
login_host: "{{ item.login_host | default('localhost') }}"
|
||||||
|
login_password: "{{ item.login_password | default(omit) }}"
|
||||||
|
login_user: "{{ item.login_user | default(postgresql_user) }}"
|
||||||
|
login_unix_socket: "{{ item.login_unix_socket | default(postgresql_unix_socket_directories[0]) }}"
|
||||||
|
port: "{{ item.port | default(omit) }}"
|
||||||
|
query: "SELECT datname FROM pg_database;"
|
||||||
|
register: postgresql_present_db_names
|
||||||
|
become: true
|
||||||
|
become_user: "{{ postgresql_user }}"
|
||||||
|
|
||||||
- name: Ensure PostgreSQL databases are present.
|
- name: Ensure PostgreSQL databases are present.
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
name: "{{ item.name }}"
|
name: "{{ item.name }}"
|
||||||
|
@ -19,3 +31,5 @@
|
||||||
# See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509
|
# See: https://github.com/ansible/ansible/issues/16048#issuecomment-229012509
|
||||||
vars:
|
vars:
|
||||||
ansible_ssh_pipelining: true
|
ansible_ssh_pipelining: true
|
||||||
|
when: "item.name not in (postgresql_present_db_names.query_result | map(attribute='datname') )"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue