diff --git a/changelogs/fragments/42-postgresql_set_add_message_when_parameter_not_found.yml b/changelogs/fragments/42-postgresql_set_add_message_when_parameter_not_found.yml new file mode 100644 index 00000000000000..fb42902d0cadbd --- /dev/null +++ b/changelogs/fragments/42-postgresql_set_add_message_when_parameter_not_found.yml @@ -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). diff --git a/lib/ansible/modules/database/postgresql/postgresql_set.py b/lib/ansible/modules/database/postgresql/postgresql_set.py index 7772fdbb3db564..787b65b77e1306 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_set.py +++ b/lib/ansible/modules/database/postgresql/postgresql_set.py @@ -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] diff --git a/test/integration/targets/postgresql/tasks/postgresql_set.yml b/test/integration/targets/postgresql/tasks/postgresql_set.yml index 01e6de1d750ce8..0f44d97caa0de1 100644 --- a/test/integration/targets/postgresql/tasks/postgresql_set.yml +++ b/test/integration/targets/postgresql/tasks/postgresql_set.yml @@ -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')