mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
postgresql_owner: add trust_input parameter (#198)
* postgresql_owner: add trust_input parameter, allow to pass values containing dots to some parameters * add changelog fragment * fix CI * fix CI
This commit is contained in:
parent
da4e5d3592
commit
5febbca503
4 changed files with 194 additions and 19 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- postgresql_owner - add the ``trust_input`` parameter (https://github.com/ansible-collections/community.general/pull/198).
|
|
@ -70,6 +70,11 @@ options:
|
||||||
- Permissions checking for SQL commands is carried out as though
|
- Permissions checking for SQL commands is carried out as though
|
||||||
the session_role were the one that had logged in originally.
|
the session_role were the one that had logged in originally.
|
||||||
type: str
|
type: str
|
||||||
|
trust_input:
|
||||||
|
description:
|
||||||
|
- If C(no), check whether values of some parameters are potentially dangerous.
|
||||||
|
type: bool
|
||||||
|
default: yes
|
||||||
seealso:
|
seealso:
|
||||||
- module: postgresql_user
|
- module: postgresql_user
|
||||||
- module: postgresql_privs
|
- module: postgresql_privs
|
||||||
|
@ -147,7 +152,10 @@ except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible_collections.community.general.plugins.module_utils.database import pg_quote_identifier
|
from ansible_collections.community.general.plugins.module_utils.database import (
|
||||||
|
check_input,
|
||||||
|
pg_quote_identifier,
|
||||||
|
)
|
||||||
from ansible_collections.community.general.plugins.module_utils.postgres import (
|
from ansible_collections.community.general.plugins.module_utils.postgres import (
|
||||||
connect_to_db,
|
connect_to_db,
|
||||||
exec_sql,
|
exec_sql,
|
||||||
|
@ -218,7 +226,7 @@ class PgOwnership(object):
|
||||||
roles = []
|
roles = []
|
||||||
for r in old_owners:
|
for r in old_owners:
|
||||||
if self.check_role_exists(r, fail_on_role):
|
if self.check_role_exists(r, fail_on_role):
|
||||||
roles.append(pg_quote_identifier(r, 'role'))
|
roles.append('"%s"' % r)
|
||||||
|
|
||||||
# Roles do not exist, nothing to do, exit:
|
# Roles do not exist, nothing to do, exit:
|
||||||
if not roles:
|
if not roles:
|
||||||
|
@ -228,7 +236,7 @@ class PgOwnership(object):
|
||||||
|
|
||||||
query = ['REASSIGN OWNED BY']
|
query = ['REASSIGN OWNED BY']
|
||||||
query.append(old_owners)
|
query.append(old_owners)
|
||||||
query.append('TO %s' % pg_quote_identifier(self.role, 'role'))
|
query.append('TO "%s"' % self.role)
|
||||||
query = ' '.join(query)
|
query = ' '.join(query)
|
||||||
|
|
||||||
self.changed = exec_sql(self, query, return_bool=True)
|
self.changed = exec_sql(self, query, return_bool=True)
|
||||||
|
@ -323,50 +331,47 @@ class PgOwnership(object):
|
||||||
|
|
||||||
def __set_db_owner(self):
|
def __set_db_owner(self):
|
||||||
"""Set the database owner."""
|
"""Set the database owner."""
|
||||||
query = "ALTER DATABASE %s OWNER TO %s" % (pg_quote_identifier(self.obj_name, 'database'),
|
query = 'ALTER DATABASE "%s" OWNER TO "%s"' % (self.obj_name, self.role)
|
||||||
pg_quote_identifier(self.role, 'role'))
|
|
||||||
self.changed = exec_sql(self, query, return_bool=True)
|
self.changed = exec_sql(self, query, return_bool=True)
|
||||||
|
|
||||||
def __set_func_owner(self):
|
def __set_func_owner(self):
|
||||||
"""Set the function owner."""
|
"""Set the function owner."""
|
||||||
query = "ALTER FUNCTION %s OWNER TO %s" % (self.obj_name,
|
query = 'ALTER FUNCTION %s OWNER TO "%s"' % (self.obj_name, self.role)
|
||||||
pg_quote_identifier(self.role, 'role'))
|
|
||||||
self.changed = exec_sql(self, query, return_bool=True)
|
self.changed = exec_sql(self, query, return_bool=True)
|
||||||
|
|
||||||
def __set_seq_owner(self):
|
def __set_seq_owner(self):
|
||||||
"""Set the sequence owner."""
|
"""Set the sequence owner."""
|
||||||
query = "ALTER SEQUENCE %s OWNER TO %s" % (pg_quote_identifier(self.obj_name, 'table'),
|
query = 'ALTER SEQUENCE %s OWNER TO "%s"' % (pg_quote_identifier(self.obj_name, 'table'),
|
||||||
pg_quote_identifier(self.role, 'role'))
|
self.role)
|
||||||
self.changed = exec_sql(self, query, return_bool=True)
|
self.changed = exec_sql(self, query, return_bool=True)
|
||||||
|
|
||||||
def __set_schema_owner(self):
|
def __set_schema_owner(self):
|
||||||
"""Set the schema owner."""
|
"""Set the schema owner."""
|
||||||
query = "ALTER SCHEMA %s OWNER TO %s" % (pg_quote_identifier(self.obj_name, 'schema'),
|
query = 'ALTER SCHEMA %s OWNER TO "%s"' % (pg_quote_identifier(self.obj_name, 'schema'),
|
||||||
pg_quote_identifier(self.role, 'role'))
|
self.role)
|
||||||
self.changed = exec_sql(self, query, return_bool=True)
|
self.changed = exec_sql(self, query, return_bool=True)
|
||||||
|
|
||||||
def __set_table_owner(self):
|
def __set_table_owner(self):
|
||||||
"""Set the table owner."""
|
"""Set the table owner."""
|
||||||
query = "ALTER TABLE %s OWNER TO %s" % (pg_quote_identifier(self.obj_name, 'table'),
|
query = 'ALTER TABLE %s OWNER TO "%s"' % (pg_quote_identifier(self.obj_name, 'table'),
|
||||||
pg_quote_identifier(self.role, 'role'))
|
self.role)
|
||||||
self.changed = exec_sql(self, query, return_bool=True)
|
self.changed = exec_sql(self, query, return_bool=True)
|
||||||
|
|
||||||
def __set_tablespace_owner(self):
|
def __set_tablespace_owner(self):
|
||||||
"""Set the tablespace owner."""
|
"""Set the tablespace owner."""
|
||||||
query = "ALTER TABLESPACE %s OWNER TO %s" % (pg_quote_identifier(self.obj_name, 'database'),
|
query = 'ALTER TABLESPACE "%s" OWNER TO "%s"' % (self.obj_name, self.role)
|
||||||
pg_quote_identifier(self.role, 'role'))
|
|
||||||
self.changed = exec_sql(self, query, return_bool=True)
|
self.changed = exec_sql(self, query, return_bool=True)
|
||||||
|
|
||||||
def __set_view_owner(self):
|
def __set_view_owner(self):
|
||||||
"""Set the view owner."""
|
"""Set the view owner."""
|
||||||
query = "ALTER VIEW %s OWNER TO %s" % (pg_quote_identifier(self.obj_name, 'table'),
|
query = 'ALTER VIEW %s OWNER TO "%s"' % (pg_quote_identifier(self.obj_name, 'table'),
|
||||||
pg_quote_identifier(self.role, 'role'))
|
self.role)
|
||||||
self.changed = exec_sql(self, query, return_bool=True)
|
self.changed = exec_sql(self, query, return_bool=True)
|
||||||
|
|
||||||
def __set_mat_view_owner(self):
|
def __set_mat_view_owner(self):
|
||||||
"""Set the materialized view owner."""
|
"""Set the materialized view owner."""
|
||||||
query = "ALTER MATERIALIZED VIEW %s OWNER TO %s" % (pg_quote_identifier(self.obj_name, 'table'),
|
query = 'ALTER MATERIALIZED VIEW %s OWNER TO "%s"' % (pg_quote_identifier(self.obj_name, 'table'),
|
||||||
pg_quote_identifier(self.role, 'role'))
|
self.role)
|
||||||
self.changed = exec_sql(self, query, return_bool=True)
|
self.changed = exec_sql(self, query, return_bool=True)
|
||||||
|
|
||||||
def __role_exists(self, role):
|
def __role_exists(self, role):
|
||||||
|
@ -392,6 +397,7 @@ def main():
|
||||||
fail_on_role=dict(type='bool', default=True),
|
fail_on_role=dict(type='bool', default=True),
|
||||||
db=dict(type='str', aliases=['login_db']),
|
db=dict(type='str', aliases=['login_db']),
|
||||||
session_role=dict(type='str'),
|
session_role=dict(type='str'),
|
||||||
|
trust_input=dict(type='bool', default=True),
|
||||||
)
|
)
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
|
@ -409,6 +415,11 @@ def main():
|
||||||
obj_type = module.params['obj_type']
|
obj_type = module.params['obj_type']
|
||||||
reassign_owned_by = module.params['reassign_owned_by']
|
reassign_owned_by = module.params['reassign_owned_by']
|
||||||
fail_on_role = module.params['fail_on_role']
|
fail_on_role = module.params['fail_on_role']
|
||||||
|
session_role = module.params['session_role']
|
||||||
|
trust_input = module.params['trust_input']
|
||||||
|
if not trust_input:
|
||||||
|
# Check input for potentially dangerous elements:
|
||||||
|
check_input(module, new_owner, obj_name, reassign_owned_by, session_role)
|
||||||
|
|
||||||
conn_params = get_conn_params(module, module.params)
|
conn_params = get_conn_params(module, module.params)
|
||||||
db_connection = connect_to_db(module, conn_params, autocommit=False)
|
db_connection = connect_to_db(module, conn_params, autocommit=False)
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
test_tablespace_path: "/ssd"
|
test_tablespace_path: "/ssd"
|
||||||
|
|
||||||
|
dangerous_name: 'curious.anonymous"; SELECT * FROM information_schema.tables; --'
|
||||||
|
|
|
@ -9,12 +9,14 @@
|
||||||
with_items:
|
with_items:
|
||||||
- alice
|
- alice
|
||||||
- bob
|
- bob
|
||||||
|
|
||||||
- name: postgresql_owner - create test database
|
- name: postgresql_owner - create test database
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
postgresql_db:
|
postgresql_db:
|
||||||
login_user: '{{ pg_user }}'
|
login_user: '{{ pg_user }}'
|
||||||
db: acme
|
db: acme
|
||||||
|
|
||||||
- name: postgresql_owner - create test table
|
- name: postgresql_owner - create test table
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -22,6 +24,7 @@
|
||||||
login_user: '{{ pg_user }}'
|
login_user: '{{ pg_user }}'
|
||||||
db: acme
|
db: acme
|
||||||
query: CREATE TABLE my_table (id int)
|
query: CREATE TABLE my_table (id int)
|
||||||
|
|
||||||
- name: postgresql_owner - set owner
|
- name: postgresql_owner - set owner
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -31,6 +34,7 @@
|
||||||
new_owner: bob
|
new_owner: bob
|
||||||
obj_name: my_table
|
obj_name: my_table
|
||||||
obj_type: table
|
obj_type: table
|
||||||
|
|
||||||
- name: postgresql_owner - create test sequence
|
- name: postgresql_owner - create test sequence
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -38,6 +42,7 @@
|
||||||
login_user: '{{ pg_user }}'
|
login_user: '{{ pg_user }}'
|
||||||
db: acme
|
db: acme
|
||||||
query: CREATE SEQUENCE test_seq
|
query: CREATE SEQUENCE test_seq
|
||||||
|
|
||||||
- name: postgresql_owner - create test function
|
- name: postgresql_owner - create test function
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -45,6 +50,7 @@
|
||||||
login_user: '{{ pg_user }}'
|
login_user: '{{ pg_user }}'
|
||||||
db: acme
|
db: acme
|
||||||
query: CREATE FUNCTION increment(integer) RETURNS integer AS 'select $1 + 1;' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT;
|
query: CREATE FUNCTION increment(integer) RETURNS integer AS 'select $1 + 1;' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT;
|
||||||
|
|
||||||
- name: postgresql_owner - create test schema
|
- name: postgresql_owner - create test schema
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -52,6 +58,7 @@
|
||||||
login_user: '{{ pg_user }}'
|
login_user: '{{ pg_user }}'
|
||||||
db: acme
|
db: acme
|
||||||
query: CREATE SCHEMA test_schema
|
query: CREATE SCHEMA test_schema
|
||||||
|
|
||||||
- name: postgresql_owner - create test view
|
- name: postgresql_owner - create test view
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -59,6 +66,7 @@
|
||||||
login_user: '{{ pg_user }}'
|
login_user: '{{ pg_user }}'
|
||||||
db: acme
|
db: acme
|
||||||
query: CREATE VIEW test_view AS SELECT * FROM my_table
|
query: CREATE VIEW test_view AS SELECT * FROM my_table
|
||||||
|
|
||||||
- name: postgresql_owner - create test materialized view
|
- name: postgresql_owner - create test materialized view
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -67,16 +75,19 @@
|
||||||
db: acme
|
db: acme
|
||||||
query: CREATE MATERIALIZED VIEW test_mat_view AS SELECT * FROM my_table
|
query: CREATE MATERIALIZED VIEW test_mat_view AS SELECT * FROM my_table
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - drop dir for test tablespace
|
- name: postgresql_owner - drop dir for test tablespace
|
||||||
become: true
|
become: true
|
||||||
file:
|
file:
|
||||||
path: '{{ test_tablespace_path }}'
|
path: '{{ test_tablespace_path }}'
|
||||||
state: absent
|
state: absent
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: postgresql_owner - disable selinux
|
- name: postgresql_owner - disable selinux
|
||||||
become: true
|
become: true
|
||||||
shell: setenforce 0
|
shell: setenforce 0
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: postgresql_owner - create dir for test tablespace
|
- name: postgresql_owner - create dir for test tablespace
|
||||||
become: true
|
become: true
|
||||||
file:
|
file:
|
||||||
|
@ -86,6 +97,7 @@
|
||||||
group: '{{ pg_user }}'
|
group: '{{ pg_user }}'
|
||||||
mode: '0700'
|
mode: '0700'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- name: postgresql_owner - create a new tablespace called acme and set bob as an its owner
|
- name: postgresql_owner - create a new tablespace called acme and set bob as an its owner
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -95,6 +107,7 @@
|
||||||
name: acme
|
name: acme
|
||||||
owner: alice
|
owner: alice
|
||||||
location: '{{ test_tablespace_path }}'
|
location: '{{ test_tablespace_path }}'
|
||||||
|
|
||||||
- name: postgresql_owner - reassign_owned_by to non existent user
|
- name: postgresql_owner - reassign_owned_by to non existent user
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -105,9 +118,11 @@
|
||||||
reassign_owned_by: bob
|
reassign_owned_by: bob
|
||||||
register: result
|
register: result
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.failed == true
|
- result.failed == true
|
||||||
|
|
||||||
- name: postgresql_owner - reassign_owned_by, check fail_on_role
|
- name: postgresql_owner - reassign_owned_by, check fail_on_role
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -118,9 +133,11 @@
|
||||||
reassign_owned_by: non_existent
|
reassign_owned_by: non_existent
|
||||||
fail_on_role: false
|
fail_on_role: false
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.failed == false
|
- result.failed == false
|
||||||
|
|
||||||
- name: postgresql_owner - reassign_owned_by in check_mode
|
- name: postgresql_owner - reassign_owned_by in check_mode
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -131,10 +148,12 @@
|
||||||
reassign_owned_by: bob
|
reassign_owned_by: bob
|
||||||
check_mode: true
|
check_mode: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['REASSIGN OWNED BY "bob" TO "alice"']
|
- result.queries == ['REASSIGN OWNED BY "bob" TO "alice"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that nothing changed after the previous step
|
- name: postgresql_owner - check that nothing changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -144,9 +163,11 @@
|
||||||
query: SELECT 1 FROM pg_tables WHERE tablename = 'my_table' AND tableowner = 'alice'
|
query: SELECT 1 FROM pg_tables WHERE tablename = 'my_table' AND tableowner = 'alice'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 0
|
- result.rowcount == 0
|
||||||
|
|
||||||
- name: postgresql_owner - reassign_owned_by
|
- name: postgresql_owner - reassign_owned_by
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -155,11 +176,14 @@
|
||||||
db: acme
|
db: acme
|
||||||
new_owner: alice
|
new_owner: alice
|
||||||
reassign_owned_by: bob
|
reassign_owned_by: bob
|
||||||
|
trust_input: yes
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['REASSIGN OWNED BY "bob" TO "alice"']
|
- result.queries == ['REASSIGN OWNED BY "bob" TO "alice"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that ownership has been changed after the previous step
|
- name: postgresql_owner - check that ownership has been changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -169,9 +193,48 @@
|
||||||
query: SELECT 1 FROM pg_tables WHERE tablename = 'my_table' AND tableowner = 'alice'
|
query: SELECT 1 FROM pg_tables WHERE tablename = 'my_table' AND tableowner = 'alice'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
|
###########################
|
||||||
|
# Test trust_inpt parameter
|
||||||
|
|
||||||
|
- name: postgresql_owner - reassign_owned_by, trust_input no
|
||||||
|
become_user: '{{ pg_user }}'
|
||||||
|
become: true
|
||||||
|
postgresql_owner:
|
||||||
|
login_user: '{{ pg_user }}'
|
||||||
|
db: acme
|
||||||
|
new_owner: '{{ dangerous_name }}'
|
||||||
|
reassign_owned_by: alice
|
||||||
|
trust_input: no
|
||||||
|
register: result
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- result is failed
|
||||||
|
- result.msg == 'Passed input \'{{ dangerous_name }}\' is potentially dangerous'
|
||||||
|
|
||||||
|
- name: postgresql_owner - reassign_owned_by, trust_input yes by default
|
||||||
|
become_user: '{{ pg_user }}'
|
||||||
|
become: true
|
||||||
|
postgresql_owner:
|
||||||
|
login_user: '{{ pg_user }}'
|
||||||
|
db: acme
|
||||||
|
new_owner: '{{ dangerous_name }}'
|
||||||
|
reassign_owned_by: alice
|
||||||
|
register: result
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- result is not changed
|
||||||
|
- result.msg is search('does not exist')
|
||||||
|
# End of testing trust_input
|
||||||
|
|
||||||
- name: postgresql_owner - set db owner in check_mode
|
- name: postgresql_owner - set db owner in check_mode
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -183,10 +246,12 @@
|
||||||
obj_type: database
|
obj_type: database
|
||||||
check_mode: true
|
check_mode: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER DATABASE "acme" OWNER TO "bob"']
|
- result.queries == ['ALTER DATABASE "acme" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that nothing changed after the previous step
|
- name: postgresql_owner - check that nothing changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -196,9 +261,11 @@
|
||||||
query: SELECT 1 FROM pg_database AS d JOIN pg_roles AS r ON d.datdba = r.oid WHERE d.datname = 'acme' AND r.rolname = 'bob'
|
query: SELECT 1 FROM pg_database AS d JOIN pg_roles AS r ON d.datdba = r.oid WHERE d.datname = 'acme' AND r.rolname = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 0
|
- result.rowcount == 0
|
||||||
|
|
||||||
- name: postgresql_owner - set db owner
|
- name: postgresql_owner - set db owner
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -209,10 +276,12 @@
|
||||||
obj_name: acme
|
obj_name: acme
|
||||||
obj_type: database
|
obj_type: database
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER DATABASE "acme" OWNER TO "bob"']
|
- result.queries == ['ALTER DATABASE "acme" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that db owner has been changed after the previous step
|
- name: postgresql_owner - check that db owner has been changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -222,9 +291,11 @@
|
||||||
query: SELECT 1 FROM pg_database AS d JOIN pg_roles AS r ON d.datdba = r.oid WHERE d.datname = 'acme' AND r.rolname = 'bob'
|
query: SELECT 1 FROM pg_database AS d JOIN pg_roles AS r ON d.datdba = r.oid WHERE d.datname = 'acme' AND r.rolname = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - set db owner again
|
- name: postgresql_owner - set db owner again
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -235,10 +306,12 @@
|
||||||
obj_name: acme
|
obj_name: acme
|
||||||
obj_type: database
|
obj_type: database
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is not changed
|
||||||
- result.queries == []
|
- result.queries == []
|
||||||
|
|
||||||
- name: postgresql_owner - check that db owner is bob
|
- name: postgresql_owner - check that db owner is bob
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -248,9 +321,11 @@
|
||||||
query: SELECT 1 FROM pg_database AS d JOIN pg_roles AS r ON d.datdba = r.oid WHERE d.datname = 'acme' AND r.rolname = 'bob'
|
query: SELECT 1 FROM pg_database AS d JOIN pg_roles AS r ON d.datdba = r.oid WHERE d.datname = 'acme' AND r.rolname = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - set table owner in check_mode
|
- name: postgresql_owner - set table owner in check_mode
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -262,10 +337,12 @@
|
||||||
obj_type: table
|
obj_type: table
|
||||||
check_mode: true
|
check_mode: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER TABLE "my_table" OWNER TO "bob"']
|
- result.queries == ['ALTER TABLE "my_table" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that nothing changed after the previous step
|
- name: postgresql_owner - check that nothing changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -275,9 +352,11 @@
|
||||||
query: SELECT 1 FROM pg_tables WHERE tablename = 'my_table' AND tableowner = 'bob'
|
query: SELECT 1 FROM pg_tables WHERE tablename = 'my_table' AND tableowner = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 0
|
- result.rowcount == 0
|
||||||
|
|
||||||
- name: postgresql_owner - set db owner
|
- name: postgresql_owner - set db owner
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -288,10 +367,12 @@
|
||||||
obj_name: my_table
|
obj_name: my_table
|
||||||
obj_type: table
|
obj_type: table
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER TABLE "my_table" OWNER TO "bob"']
|
- result.queries == ['ALTER TABLE "my_table" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that table owner has been changed after the previous step
|
- name: postgresql_owner - check that table owner has been changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -301,9 +382,11 @@
|
||||||
query: SELECT 1 FROM pg_tables WHERE tablename = 'my_table' AND tableowner = 'bob'
|
query: SELECT 1 FROM pg_tables WHERE tablename = 'my_table' AND tableowner = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - set db owner again
|
- name: postgresql_owner - set db owner again
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -314,10 +397,12 @@
|
||||||
obj_name: my_table
|
obj_name: my_table
|
||||||
obj_type: table
|
obj_type: table
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is not changed
|
||||||
- result.queries == []
|
- result.queries == []
|
||||||
|
|
||||||
- name: postgresql_owner - check that table owner is bob
|
- name: postgresql_owner - check that table owner is bob
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -327,9 +412,11 @@
|
||||||
query: SELECT 1 FROM pg_tables WHERE tablename = 'my_table' AND tableowner = 'bob'
|
query: SELECT 1 FROM pg_tables WHERE tablename = 'my_table' AND tableowner = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - set sequence owner in check_mode
|
- name: postgresql_owner - set sequence owner in check_mode
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -341,10 +428,12 @@
|
||||||
obj_type: sequence
|
obj_type: sequence
|
||||||
check_mode: true
|
check_mode: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER SEQUENCE "test_seq" OWNER TO "bob"']
|
- result.queries == ['ALTER SEQUENCE "test_seq" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that nothing changed after the previous step
|
- name: postgresql_owner - check that nothing changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -354,9 +443,11 @@
|
||||||
query: SELECT 1 FROM pg_class AS c JOIN pg_roles AS r ON c.relowner = r.oid WHERE c.relkind = 'S' AND c.relname = 'test_seq' AND r.rolname = 'bob'
|
query: SELECT 1 FROM pg_class AS c JOIN pg_roles AS r ON c.relowner = r.oid WHERE c.relkind = 'S' AND c.relname = 'test_seq' AND r.rolname = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 0
|
- result.rowcount == 0
|
||||||
|
|
||||||
- name: postgresql_owner - set db owner
|
- name: postgresql_owner - set db owner
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -367,10 +458,12 @@
|
||||||
obj_name: test_seq
|
obj_name: test_seq
|
||||||
obj_type: sequence
|
obj_type: sequence
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER SEQUENCE "test_seq" OWNER TO "bob"']
|
- result.queries == ['ALTER SEQUENCE "test_seq" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that table owner has been changed after the previous step
|
- name: postgresql_owner - check that table owner has been changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -380,9 +473,11 @@
|
||||||
query: SELECT 1 FROM pg_class AS c JOIN pg_roles AS r ON c.relowner = r.oid WHERE c.relkind = 'S' AND c.relname = 'test_seq' AND r.rolname = 'bob'
|
query: SELECT 1 FROM pg_class AS c JOIN pg_roles AS r ON c.relowner = r.oid WHERE c.relkind = 'S' AND c.relname = 'test_seq' AND r.rolname = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - set db owner again
|
- name: postgresql_owner - set db owner again
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -393,10 +488,12 @@
|
||||||
obj_name: test_seq
|
obj_name: test_seq
|
||||||
obj_type: sequence
|
obj_type: sequence
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is not changed
|
||||||
- result.queries == []
|
- result.queries == []
|
||||||
|
|
||||||
- name: postgresql_owner - check that sequence owner is bob
|
- name: postgresql_owner - check that sequence owner is bob
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -406,9 +503,11 @@
|
||||||
query: SELECT 1 FROM pg_class AS c JOIN pg_roles AS r ON c.relowner = r.oid WHERE c.relkind = 'S' AND c.relname = 'test_seq' AND r.rolname = 'bob'
|
query: SELECT 1 FROM pg_class AS c JOIN pg_roles AS r ON c.relowner = r.oid WHERE c.relkind = 'S' AND c.relname = 'test_seq' AND r.rolname = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - set function owner in check_mode
|
- name: postgresql_owner - set function owner in check_mode
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -421,11 +520,13 @@
|
||||||
check_mode: true
|
check_mode: true
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER FUNCTION increment OWNER TO "bob"']
|
- result.queries == ['ALTER FUNCTION increment OWNER TO "bob"']
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - check that nothing changed after the previous step
|
- name: postgresql_owner - check that nothing changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -436,10 +537,12 @@
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 0
|
- result.rowcount == 0
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - set func owner
|
- name: postgresql_owner - set func owner
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -451,11 +554,13 @@
|
||||||
obj_type: function
|
obj_type: function
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER FUNCTION increment OWNER TO "bob"']
|
- result.queries == ['ALTER FUNCTION increment OWNER TO "bob"']
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - check that func owner has been changed after the previous step
|
- name: postgresql_owner - check that func owner has been changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -466,10 +571,12 @@
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - set func owner again
|
- name: postgresql_owner - set func owner again
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -481,11 +588,13 @@
|
||||||
obj_type: function
|
obj_type: function
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is not changed
|
||||||
- result.queries == []
|
- result.queries == []
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - check that function owner is bob
|
- name: postgresql_owner - check that function owner is bob
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -496,10 +605,12 @@
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
when: postgres_version_resp.stdout is version('10', '>=')
|
when: postgres_version_resp.stdout is version('10', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - set schema owner in check_mode
|
- name: postgresql_owner - set schema owner in check_mode
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -511,10 +622,12 @@
|
||||||
obj_type: schema
|
obj_type: schema
|
||||||
check_mode: true
|
check_mode: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER SCHEMA "test_schema" OWNER TO "bob"']
|
- result.queries == ['ALTER SCHEMA "test_schema" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that nothing changed after the previous step
|
- name: postgresql_owner - check that nothing changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -524,9 +637,11 @@
|
||||||
query: SELECT 1 FROM information_schema.schemata WHERE schema_name = 'test_schema' AND schema_owner = 'bob'
|
query: SELECT 1 FROM information_schema.schemata WHERE schema_name = 'test_schema' AND schema_owner = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 0
|
- result.rowcount == 0
|
||||||
|
|
||||||
- name: postgresql_owner - set schema owner
|
- name: postgresql_owner - set schema owner
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -537,10 +652,12 @@
|
||||||
obj_name: test_schema
|
obj_name: test_schema
|
||||||
obj_type: schema
|
obj_type: schema
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER SCHEMA "test_schema" OWNER TO "bob"']
|
- result.queries == ['ALTER SCHEMA "test_schema" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that schema owner has been changed after the previous step
|
- name: postgresql_owner - check that schema owner has been changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -550,9 +667,11 @@
|
||||||
query: SELECT 1 FROM information_schema.schemata WHERE schema_name = 'test_schema' AND schema_owner = 'bob'
|
query: SELECT 1 FROM information_schema.schemata WHERE schema_name = 'test_schema' AND schema_owner = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - set schema owner again
|
- name: postgresql_owner - set schema owner again
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -563,10 +682,12 @@
|
||||||
obj_name: test_seq
|
obj_name: test_seq
|
||||||
obj_type: sequence
|
obj_type: sequence
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is not changed
|
||||||
- result.queries == []
|
- result.queries == []
|
||||||
|
|
||||||
- name: postgresql_owner - check that schema owner is bob
|
- name: postgresql_owner - check that schema owner is bob
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -576,9 +697,11 @@
|
||||||
query: SELECT 1 FROM information_schema.schemata WHERE schema_name = 'test_schema' AND schema_owner = 'bob'
|
query: SELECT 1 FROM information_schema.schemata WHERE schema_name = 'test_schema' AND schema_owner = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - set view owner in check_mode
|
- name: postgresql_owner - set view owner in check_mode
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -590,10 +713,12 @@
|
||||||
obj_type: view
|
obj_type: view
|
||||||
check_mode: true
|
check_mode: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER VIEW "test_view" OWNER TO "bob"']
|
- result.queries == ['ALTER VIEW "test_view" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that nothing changed after the previous step
|
- name: postgresql_owner - check that nothing changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -603,9 +728,11 @@
|
||||||
query: SELECT 1 FROM pg_views WHERE viewname = 'test_view' AND viewowner = 'bob'
|
query: SELECT 1 FROM pg_views WHERE viewname = 'test_view' AND viewowner = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 0
|
- result.rowcount == 0
|
||||||
|
|
||||||
- name: postgresql_owner - set view owner
|
- name: postgresql_owner - set view owner
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -616,10 +743,12 @@
|
||||||
obj_name: test_view
|
obj_name: test_view
|
||||||
obj_type: view
|
obj_type: view
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER VIEW "test_view" OWNER TO "bob"']
|
- result.queries == ['ALTER VIEW "test_view" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that view owner has been changed after the previous step
|
- name: postgresql_owner - check that view owner has been changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -629,9 +758,11 @@
|
||||||
query: SELECT 1 FROM pg_views WHERE viewname = 'test_view' AND viewowner = 'bob'
|
query: SELECT 1 FROM pg_views WHERE viewname = 'test_view' AND viewowner = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - set view owner again
|
- name: postgresql_owner - set view owner again
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -642,10 +773,12 @@
|
||||||
obj_name: test_view
|
obj_name: test_view
|
||||||
obj_type: view
|
obj_type: view
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is not changed
|
||||||
- result.queries == []
|
- result.queries == []
|
||||||
|
|
||||||
- name: postgresql_owner - check that view owner is bob
|
- name: postgresql_owner - check that view owner is bob
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -655,9 +788,11 @@
|
||||||
query: SELECT 1 FROM pg_views WHERE viewname = 'test_view' AND viewowner = 'bob'
|
query: SELECT 1 FROM pg_views WHERE viewname = 'test_view' AND viewowner = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - set matview owner in check_mode
|
- name: postgresql_owner - set matview owner in check_mode
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -670,11 +805,13 @@
|
||||||
check_mode: true
|
check_mode: true
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER MATERIALIZED VIEW "test_mat_view" OWNER TO "bob"']
|
- result.queries == ['ALTER MATERIALIZED VIEW "test_mat_view" OWNER TO "bob"']
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - check that nothing changed after the previous step
|
- name: postgresql_owner - check that nothing changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -685,10 +822,12 @@
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 0
|
- result.rowcount == 0
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - set matview owner
|
- name: postgresql_owner - set matview owner
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -700,11 +839,13 @@
|
||||||
obj_type: matview
|
obj_type: matview
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER MATERIALIZED VIEW "test_mat_view" OWNER TO "bob"']
|
- result.queries == ['ALTER MATERIALIZED VIEW "test_mat_view" OWNER TO "bob"']
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - check that matview owner has been changed after the previous step
|
- name: postgresql_owner - check that matview owner has been changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -715,10 +856,12 @@
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - set matview owner again
|
- name: postgresql_owner - set matview owner again
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -730,11 +873,13 @@
|
||||||
obj_type: matview
|
obj_type: matview
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is not changed
|
||||||
- result.queries == []
|
- result.queries == []
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - check that matview owner is bob
|
- name: postgresql_owner - check that matview owner is bob
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -745,10 +890,12 @@
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
when: postgres_version_resp.stdout is version('9.4', '>=')
|
when: postgres_version_resp.stdout is version('9.4', '>=')
|
||||||
|
|
||||||
- name: postgresql_owner - set tablespace owner in check_mode
|
- name: postgresql_owner - set tablespace owner in check_mode
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -760,10 +907,12 @@
|
||||||
obj_type: tablespace
|
obj_type: tablespace
|
||||||
check_mode: true
|
check_mode: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER TABLESPACE "acme" OWNER TO "bob"']
|
- result.queries == ['ALTER TABLESPACE "acme" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that nothing changed after the previous step
|
- name: postgresql_owner - check that nothing changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -773,9 +922,11 @@
|
||||||
query: SELECT 1 FROM pg_tablespace AS t JOIN pg_roles AS r ON t.spcowner = r.oid WHERE t.spcname = 'acme' AND r.rolname = 'bob'
|
query: SELECT 1 FROM pg_tablespace AS t JOIN pg_roles AS r ON t.spcowner = r.oid WHERE t.spcname = 'acme' AND r.rolname = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 0
|
- result.rowcount == 0
|
||||||
|
|
||||||
- name: postgresql_owner - set tablespace owner
|
- name: postgresql_owner - set tablespace owner
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -786,10 +937,12 @@
|
||||||
obj_name: acme
|
obj_name: acme
|
||||||
obj_type: tablespace
|
obj_type: tablespace
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is changed
|
- result is changed
|
||||||
- result.queries == ['ALTER TABLESPACE "acme" OWNER TO "bob"']
|
- result.queries == ['ALTER TABLESPACE "acme" OWNER TO "bob"']
|
||||||
|
|
||||||
- name: postgresql_owner - check that tablespace owner has been changed after the previous step
|
- name: postgresql_owner - check that tablespace owner has been changed after the previous step
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -799,9 +952,11 @@
|
||||||
query: SELECT 1 FROM pg_tablespace AS t JOIN pg_roles AS r ON t.spcowner = r.oid WHERE t.spcname = 'acme' AND r.rolname = 'bob'
|
query: SELECT 1 FROM pg_tablespace AS t JOIN pg_roles AS r ON t.spcowner = r.oid WHERE t.spcname = 'acme' AND r.rolname = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - set tablespace owner again
|
- name: postgresql_owner - set tablespace owner again
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -812,10 +967,12 @@
|
||||||
obj_name: acme
|
obj_name: acme
|
||||||
obj_type: tablespace
|
obj_type: tablespace
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result is not changed
|
- result is not changed
|
||||||
- result.queries == []
|
- result.queries == []
|
||||||
|
|
||||||
- name: postgresql_owner - check that tablespace owner is bob
|
- name: postgresql_owner - check that tablespace owner is bob
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -825,9 +982,11 @@
|
||||||
query: SELECT 1 FROM pg_tablespace AS t JOIN pg_roles AS r ON t.spcowner = r.oid WHERE t.spcname = 'acme' AND r.rolname = 'bob'
|
query: SELECT 1 FROM pg_tablespace AS t JOIN pg_roles AS r ON t.spcowner = r.oid WHERE t.spcname = 'acme' AND r.rolname = 'bob'
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- result.rowcount == 1
|
- result.rowcount == 1
|
||||||
|
|
||||||
- name: postgresql_owner - create test database
|
- name: postgresql_owner - create test database
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
@ -835,6 +994,7 @@
|
||||||
login_user: '{{ pg_user }}'
|
login_user: '{{ pg_user }}'
|
||||||
db: acme
|
db: acme
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: postgresql_owner - drop test tablespace
|
- name: postgresql_owner - drop test tablespace
|
||||||
become_user: '{{ pg_user }}'
|
become_user: '{{ pg_user }}'
|
||||||
become: true
|
become: true
|
||||||
|
|
Loading…
Reference in a new issue