Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ty.postgresql

* 'main' of https://github.com/ansible-collections/community.postgresql:
  Remove changelog fragment for doc change.
  Update changelog to reflect doc changes for postgresql_owner.py
  Change documentation to be more clear that the changes take place for the entire cluster/instance rather than just a single DB.
  Fix `nonetype` by adding `ensure_required_libs` to `get_conn_params` in postgres.py (ansible-collections#253)
  Update unit tests (ansible-collections#258)
  docs: announce the new matrix pg room (ansible-collections#254)
  • Loading branch information
jchancojr committed May 7, 2022
2 parents ae10d39 + 17f1893 commit 7b958ce
Show file tree
Hide file tree
Showing 25 changed files with 66 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ They also should be subscribed to Ansible's [The Bullhorn newsletter](https://do

We announce important development changes and releases through Ansible's [The Bullhorn newsletter](https://docs.ansible.com/ansible/devel/community/communication.html#the-bullhorn). If you are a collection developer, be sure you are subscribed.

Join us in the `#ansible` (general use questions and support), `#ansible-community` (community and collection development questions), and other [IRC channels](https://docs.ansible.com/ansible/devel/community/communication.html#irc-channels) on [Libera.Chat](https://libera.chat).
Join us in the `#postgresql:ansible.com` [room](https://matrix.to/#/#postgresql:ansible.com) on Matrix, the `#ansible` (general use questions and support), `#ansible-community` (community and collection development questions), and other [IRC channels](https://docs.ansible.com/ansible/devel/community/communication.html#irc-channels) on [Libera.Chat](https://libera.chat).

We take part in the global quarterly [Ansible Contributor Summit](https://github.com/ansible/community/wiki/Contributor-Summit) virtually or in-person. Track [The Bullhorn newsletter](https://docs.ansible.com/ansible/devel/community/communication.html#the-bullhorn) and join us.

Expand Down
2 changes: 2 additions & 0 deletions changelogs/fragments/252-fix-none-attribute-error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- collection core functions - fix attribute error `nonetype` by always calling `ensure_required_libs` (https://github.com/ansible-collections/community.postgresql/issues/252).
2 changes: 1 addition & 1 deletion docs/docsite/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extra_links:
communication:
matrix_rooms:
- topic: General usage and support questions
room: '#users:ansible.im'
room: '#postgresql:ansible.com'
irc_channels:
- topic: General usage and support questions
network: Libera
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def connect_to_db(module, conn_params, autocommit=False, fail_on_conn=True):
autocommit (bool) -- commit automatically (default False)
fail_on_conn (bool) -- fail if connection failed or just warn and return None (default True)
"""
ensure_required_libs(module)

db_connection = None
conn_err = None
Expand Down Expand Up @@ -177,6 +176,7 @@ def get_conn_params(module, params_dict, warn_db_default=True):
Kwargs:
warn_db_default (bool) -- warn that the default DB is used (default True)
"""

# To use defaults values, keyword arguments must be absent, so
# check which values are empty and don't include in the return dictionary
params_map = {
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
exec_sql,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -377,6 +378,8 @@ def main():
elif module.params.get('copy_to') and not module.params.get('src'):
module.fail_json(msg='src param is necessary with copy_to')

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
# Connect to DB and make cursor object:
conn_params = get_conn_params(module, module.params)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=False)
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
)
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -397,6 +398,8 @@ def main():
if version and state == 'absent':
module.warn("Parameter version is ignored when state=absent")

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=True)
cursor = db_connection.cursor(cursor_factory=DictCursor)
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_idx.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
exec_sql,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -517,6 +518,8 @@ def main():
if cascade and state != 'absent':
module.fail_json(msg="cascade parameter used only with state=absent")

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=True)
cursor = db_connection.cursor(cursor_factory=DictCursor)
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@
)
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -550,6 +551,8 @@ def connect(self, fail_on_conn=True):
Note: connection parameters are passed by self.module object.
"""
# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(self.module)
conn_params = get_conn_params(self.module, self.module.params, warn_db_default=False)
self.db_conn, dummy = connect_to_db(self.module, conn_params, fail_on_conn=fail_on_conn)
if self.db_conn is None:
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.database import check_input
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -308,6 +309,8 @@ def main():
# Check input for potentially dangerous elements:
check_input(module, lang, session_role, owner)

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=False)
cursor = db_connection.cursor()
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.database import check_input
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
ensure_required_libs,
get_conn_params,
PgMembership,
postgres_common_argument_spec,
Expand Down Expand Up @@ -184,6 +185,8 @@ def main():
# Check input for potentially dangerous elements:
check_input(module, groups, target_roles, session_role)

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params, warn_db_default=False)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=False)
cursor = db_connection.cursor(cursor_factory=DictCursor)
Expand Down
5 changes: 4 additions & 1 deletion plugins/modules/postgresql_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
description:
- The list of role names. The ownership of all the objects within the current database,
and of all shared objects (databases, tablespaces), owned by this role(s) will be reassigned to I(owner).
- Pay attention - it reassigns all objects owned by this role(s) in the I(db)!
- Pay attention - it reassigns all objects owned by this role(s) in the I(instance)!
- If role(s) exists, always returns changed True.
- Cannot reassign ownership of objects that are required by the database system.
- Mutually exclusive with C(obj_type).
Expand Down Expand Up @@ -157,6 +157,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
exec_sql,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -419,6 +420,8 @@ def main():
# Check input for potentially dangerous elements:
check_input(module, new_owner, obj_name, reassign_owned_by, session_role)

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=False)
cursor = db_connection.cursor(cursor_factory=DictCursor)
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
exec_sql,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -186,6 +187,8 @@ def main():
conn_err_msg='',
)

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params, warn_db_default=False)
db_connection, err = connect_to_db(module, conn_params, fail_on_conn=False)
if err:
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
exec_sql,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -633,6 +634,8 @@ def main():
if state == 'present' and cascade:
module.warn('parameter "cascade" is ignored when "state=present"')

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
# Connect to DB and make cursor object:
conn_params = get_conn_params(module, module.params)
# We check publication state without DML queries execution, so set autocommit:
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@
connect_to_db,
convert_elements_to_pg_arrays,
convert_to_supported,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
set_search_path,
Expand Down Expand Up @@ -401,6 +402,8 @@ def main():
else:
query_list.append(query)

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=autocommit)
if encoding is not None:
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -255,6 +256,8 @@ def main():

changed = False

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=True)
cursor = db_connection.cursor(cursor_factory=DictCursor)
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
connect_to_db,
convert_elements_to_pg_arrays,
convert_to_supported,
ensure_required_libs,
get_conn_params,
list_to_pg_array,
postgres_common_argument_spec,
Expand Down Expand Up @@ -279,6 +280,8 @@ def main():
except Exception as e:
module.fail_json(msg="Cannot read file '%s' : %s" % (path, to_native(e)))

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=True)
if encoding is not None:
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
exec_sql,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -532,6 +533,8 @@ def main():

# Change autocommit to False if check_mode:
autocommit = not module.check_mode
# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
# Connect to DB and make cursor object:
conn_params = get_conn_params(module, module.params)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=autocommit)
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
)
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -371,6 +372,8 @@ def main():
if value is None and not reset:
module.fail_json(msg="%s: at least one of value or reset param must be specified" % name)

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params, warn_db_default=False)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=True)
cursor = db_connection.cursor(cursor_factory=DictCursor)
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_slot.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
exec_sql,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -268,6 +269,8 @@ def main():
else:
warn_db_default = False

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params, warn_db_default=warn_db_default)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=True)
cursor = db_connection.cursor(cursor_factory=DictCursor)
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
exec_sql,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -643,6 +644,8 @@ def main():
if subsparams:
module.warn("parameter 'subsparams' is ignored when state is not 'present'")

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
# Connect to DB and make cursor object:
pg_conn_params = get_conn_params(module, module.params)
# We check subscription state without DML queries execution, so set autocommit:
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
exec_sql,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -530,6 +531,8 @@ def main():
if including and not like:
module.fail_json(msg="%s: including param needs like param specified" % table)

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=False)
cursor = db_connection.cursor(cursor_factory=DictCursor)
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_tablespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
exec_sql,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -427,6 +428,8 @@ def main():
check_input(module, tablespace, location, owner,
rename_to, session_role, settings_list)

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params, warn_db_default=False)
db_connection, dummy = connect_to_db(module, conn_params, autocommit=True)
cursor = db_connection.cursor(cursor_factory=DictCursor)
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
)
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
ensure_required_libs,
get_conn_params,
get_server_version,
PgMembership,
Expand Down Expand Up @@ -951,6 +952,8 @@ def main():
check_input(module, user, password, privs, expires,
role_attr_flags, groups, comment, session_role)

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
conn_params = get_conn_params(module, module.params, warn_db_default=False)
db_connection, dummy = connect_to_db(module, conn_params)
cursor = db_connection.cursor(cursor_factory=DictCursor)
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/postgresql_user_obj_stat_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
connect_to_db,
exec_sql,
ensure_required_libs,
get_conn_params,
postgres_common_argument_spec,
)
Expand Down Expand Up @@ -312,6 +313,8 @@ def main():
if not module.params["trust_input"]:
check_input(module, module.params['session_role'])

# Ensure psycopg2 libraries are available before connecting to DB:
ensure_required_libs(module)
# Connect to DB and make cursor object:
pg_conn_params = get_conn_params(module, module.params)
# We don't need to commit anything, so, set it to False:
Expand Down
Loading

0 comments on commit 7b958ce

Please sign in to comment.