1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/postgresql_db/tasks/postgresql_db_general.yml
Ansible Core Team aebc1b03fd Initial commit
2020-03-09 09:11:07 +00:00

152 lines
4.7 KiB
YAML

- become_user: '{{ pg_user }}'
become: true
vars:
db_tablespace: bar
tblspc_location: /ssd
db_name: acme
block_parameters:
become_user: '{{ pg_user }}'
become: true
task_parameters:
register: result
pg_parameters:
login_user: '{{ pg_user }}'
block:
- name: postgresql_db - drop dir for test tablespace
become: true
become_user: root
file:
path: '{{ tblspc_location }}'
state: absent
ignore_errors: true
- name: postgresql_db - disable selinux
become: true
become_user: root
shell: setenforce 0
ignore_errors: true
- name: postgresql_db - create dir for test tablespace
become: true
become_user: root
file:
path: '{{ tblspc_location }}'
state: directory
owner: '{{ pg_user }}'
group: '{{ pg_user }}'
mode: '0700'
- name: postgresql_db_ - create a new tablespace
postgresql_tablespace:
login_user: '{{ pg_user }}'
login_db: postgres
name: '{{ db_tablespace }}'
location: '{{ tblspc_location }}'
- register: result
name: postgresql_db_tablespace - Create DB with tablespace option in check mode
check_mode: true
postgresql_db:
login_user: '{{ pg_user }}'
maintenance_db: postgres
name: '{{ db_name }}'
tablespace: '{{ db_tablespace }}'
- assert:
that:
- result is changed
- register: result
name: postgresql_db_tablespace - Check actual DB tablespace, rowcount must be 0 because actually nothing changed
postgresql_query:
login_user: '{{ pg_user }}'
login_db: postgres
query: 'SELECT 1 FROM pg_database AS d JOIN pg_tablespace AS t ON d.dattablespace = t.oid WHERE d.datname = ''{{ db_name }}'' AND t.spcname = ''{{ db_tablespace }}''
'
- assert:
that:
- result.rowcount == 0
- register: result
name: postgresql_db_tablespace - Create DB with tablespace option
postgresql_db:
login_user: '{{ pg_user }}'
maintenance_db: postgres
name: '{{ db_name }}'
tablespace: '{{ db_tablespace }}'
- assert:
that:
- result is changed
- result.executed_commands == ['CREATE DATABASE "{{ db_name }}" TABLESPACE "{{ db_tablespace }}"']
- register: result
name: postgresql_db_tablespace - Check actual DB tablespace, rowcount must be 1
postgresql_query:
login_user: '{{ pg_user }}'
login_db: postgres
query: 'SELECT 1 FROM pg_database AS d JOIN pg_tablespace AS t ON d.dattablespace = t.oid WHERE d.datname = ''{{ db_name }}'' AND t.spcname = ''{{ db_tablespace }}''
'
- assert:
that:
- result.rowcount == 1
- register: result
name: postgresql_db_tablespace - The same DB with tablespace option again
postgresql_db:
login_user: '{{ pg_user }}'
maintenance_db: postgres
name: '{{ db_name }}'
tablespace: '{{ db_tablespace }}'
- assert:
that:
- result is not changed
- register: result
name: postgresql_db_tablespace - Change tablespace in check_mode
check_mode: true
postgresql_db:
login_user: '{{ pg_user }}'
maintenance_db: postgres
name: '{{ db_name }}'
tablespace: pg_default
- assert:
that:
- result is changed
- register: result
name: postgresql_db_tablespace - Check actual DB tablespace, rowcount must be 1 because actually nothing changed
postgresql_query:
login_user: '{{ pg_user }}'
login_db: postgres
query: 'SELECT 1 FROM pg_database AS d JOIN pg_tablespace AS t ON d.dattablespace = t.oid WHERE d.datname = ''{{ db_name }}'' AND t.spcname = ''{{ db_tablespace }}''
'
- assert:
that:
- result.rowcount == 1
- register: result
name: postgresql_db_tablespace - Change tablespace in actual mode
postgresql_db:
login_user: '{{ pg_user }}'
maintenance_db: postgres
name: '{{ db_name }}'
tablespace: pg_default
- assert:
that:
- result is changed
- register: result
name: postgresql_db_tablespace - Check actual DB tablespace, rowcount must be 1
postgresql_query:
login_user: '{{ pg_user }}'
login_db: postgres
query: 'SELECT 1 FROM pg_database AS d JOIN pg_tablespace AS t ON d.dattablespace = t.oid WHERE d.datname = ''{{ db_name }}'' AND t.spcname = ''pg_default''
'
- assert:
that:
- result.rowcount == 1
- register: result
name: postgresql_db_tablespace - Drop test DB
postgresql_db:
login_user: '{{ pg_user }}'
maintenance_db: postgres
name: '{{ db_name }}'
state: absent
- register: result
name: postgresql_db_tablespace - Remove tablespace
postgresql_tablespace:
login_user: '{{ pg_user }}'
login_db: postgres
name: '{{ db_tablespace }}'
state: absent