Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.9] postgresql_set: Return a message when a passed parameter has not been found #73286

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,2 @@
bugfixes:
- postgresql_set - return a message instead of traceback when a passed parameter has not been found (https://github.com/ansible-collections/community.postgresql/issues/41).
5 changes: 5 additions & 0 deletions lib/ansible/modules/database/postgresql/postgresql_set.py
Expand Up @@ -195,6 +195,11 @@ def param_get(cursor, module, name):
except Exception as e:
module.fail_json(msg="Unable to get %s value due to : %s" % (name, to_native(e)))

if not info:
module.fail_json(msg="No such parameter: %s. "
"Please check its spelling or presence in your PostgreSQL version "
"(https://www.postgresql.org/docs/current/runtime-config.html)" % name)

raw_val = info[0][1]
unit = info[0][2]
context = info[0][3]
Expand Down
16 changes: 16 additions & 0 deletions test/integration/targets/postgresql/tasks/postgresql_set.yml
Expand Up @@ -302,3 +302,19 @@
- assert:
that:
- result.query_result.0.reset_val == "test ! -f /mnt/postgres/mb/%f && cp %p /mnt/postgres/mb/%f"

#################################################################################
# Bugfix of https://github.com/ansible-collections/community.postgresql/issues/41
- name: Pass non-existent parameter
<<: *task_parameters
postgresql_set:
<<: *pg_parameters
name: Timezone
value: utc
register: result
ignore_errors: yes

- assert:
that:
- result is failed
- result.msg is search('No such parameter')