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_tablespace/tasks/postgresql_tablespace_initial.yml
Andrew Klychkov 01eee507f2
postgresql_tablespace: add trust_input parameter (#240)
* postgresql_tablespace: add trust_input parameter

* add changelog fragment
2020-05-01 14:10:13 +03:00

245 lines
6 KiB
YAML

- name: postgresql_tablespace - drop dir for test tablespace
become: true
file:
path: '{{ test_tablespace_path }}'
state: absent
ignore_errors: true
- name: postgresql_tablespace - disable selinux
become: true
shell: setenforce 0
ignore_errors: true
- name: postgresql_tablespace - create dir for test tablespace
become: true
file:
path: '{{ test_tablespace_path }}'
state: directory
owner: '{{ pg_user }}'
group: '{{ pg_user }}'
mode: '0700'
ignore_errors: true
- name: postgresql_tablespace - create test role to test change ownership
become_user: '{{ pg_user }}'
become: true
postgresql_user:
db: postgres
login_user: '{{ pg_user }}'
name: bob
state: present
ignore_errors: true
- name: postgresql_tablespace - create test role to test change ownership
become_user: '{{ pg_user }}'
become: true
postgresql_user:
db: postgres
login_user: '{{ pg_user }}'
name: alice
state: present
ignore_errors: true
- name: postgresql_tablespace - create a new tablespace called acme and set bob as an its owner
become_user: '{{ pg_user }}'
become: true
postgresql_tablespace:
db: postgres
login_user: '{{ pg_user }}'
name: acme
owner: bob
location: /ssd
register: result
ignore_errors: true
- assert:
that:
- result is changed
- result.owner == 'bob'
- result.queries == ["CREATE TABLESPACE \"acme\" LOCATION '/ssd'", "ALTER TABLESPACE \"acme\" OWNER TO \"bob\""]
- result.state == 'present'
- result.tablespace == 'acme'
- result.options == {}
- result.location == '/ssd'
- name: postgresql_tablespace - try to create the same tablespace with different location
become_user: '{{ pg_user }}'
become: true
postgresql_tablespace:
db: postgres
login_user: '{{ pg_user }}'
name: acme
location: /another-ssd
register: result
ignore_errors: true
- assert:
that:
- result is not changed
- result.msg == "Tablespace 'acme' exists with different location '/ssd'"
- name: postgresql_tablespace - change tablespace owner to alice
become_user: '{{ pg_user }}'
become: true
postgresql_tablespace:
db: postgres
login_user: '{{ pg_user }}'
name: acme
owner: alice
register: result
ignore_errors: true
- assert:
that:
- result is changed
- result.owner == 'alice'
- result.queries == ["ALTER TABLESPACE \"acme\" OWNER TO \"alice\""]
- result.state == 'present'
- result.tablespace == 'acme'
- result.options == {}
- name: postgresql_tablespace - try to change tablespace owner to alice again to be sure that nothing changes
become_user: '{{ pg_user }}'
become: true
postgresql_tablespace:
db: postgres
login_user: '{{ pg_user }}'
name: acme
owner: alice
register: result
ignore_errors: true
- assert:
that:
- result is not changed
- result.owner == 'alice'
- result.queries == []
- result.state == 'present'
- result.tablespace == 'acme'
- result.options == {}
- name: postgresql_tablespace - change tablespace options
become_user: '{{ pg_user }}'
become: true
postgresql_tablespace:
db: postgres
login_user: '{{ pg_user }}'
name: acme
set:
seq_page_cost: 4
register: result
ignore_errors: true
- assert:
that:
- result is changed
- result.owner == 'alice'
- result.queries == ["ALTER TABLESPACE \"acme\" SET (seq_page_cost = '4')"]
- result.state == 'present'
- result.tablespace == 'acme'
- result.options.seq_page_cost == '4'
when: postgres_version_resp.stdout is version('9.0', '>=')
- name: postgresql_tablespace - reset seq_page_cost option
become_user: '{{ pg_user }}'
become: true
postgresql_tablespace:
login_db: postgres
login_user: '{{ pg_user }}'
name: acme
set:
seq_page_cost: reset
register: result
ignore_errors: true
- assert:
that:
- result is changed
- result.queries == ["ALTER TABLESPACE \"acme\" RESET (seq_page_cost)"]
when: postgres_version_resp.stdout is version('9.0', '>=')
- name: postgresql_tablespace - reset seq_page_cost option again
become_user: '{{ pg_user }}'
become: true
postgresql_tablespace:
db: postgres
login_user: '{{ pg_user }}'
name: acme
set:
seq_page_cost: reset
register: result
ignore_errors: true
- assert:
that:
- result is not changed
- result.queries == []
when: postgres_version_resp.stdout is version('9.0', '>=')
- name: postgresql_tablespace - rename tablespace
become_user: '{{ pg_user }}'
become: true
postgresql_tablespace:
db: postgres
login_user: '{{ pg_user }}'
name: acme
rename_to: foo
register: result
ignore_errors: true
- assert:
that:
- result is changed
- result.newname == 'foo'
- result.queries == ["ALTER TABLESPACE \"acme\" RENAME TO \"foo\""]
- name: postgresql_tablespace - rename tablespace to potentially dangerous name
become_user: '{{ pg_user }}'
become: true
postgresql_tablespace:
db: postgres
login_user: '{{ pg_user }}'
name: foo
rename_to: '{{ dangerous_name }}'
trust_input: no
register: result
ignore_errors: true
- assert:
that:
- result is failed
- result.msg == 'Passed input \'{{ dangerous_name }}\' is potentially dangerous'
- name: postgresql_tablespace - drop tablespace
become_user: '{{ pg_user }}'
become: true
postgresql_tablespace:
db: postgres
login_user: '{{ pg_user }}'
name: foo
state: absent
trust_input: yes
register: result
ignore_errors: true
- assert:
that:
- result is changed
- result.state == 'absent'
- result.queries == ["DROP TABLESPACE \"foo\""]
- name: postgresql_tablespace - try to drop nonexistent tablespace
become_user: '{{ pg_user }}'
become: true
postgresql_tablespace:
db: postgres
login_user: '{{ pg_user }}'
name: foo
state: absent
register: result
ignore_errors: true
- assert:
that:
- result is not changed
- result.msg == "Tries to drop nonexistent tablespace 'foo'"