diff --git a/changelogs/fragments/40424_postgresql_db_not_failed_when_dump_err.yml b/changelogs/fragments/40424_postgresql_db_not_failed_when_dump_err.yml new file mode 100644 index 00000000000..9be407bf4ea --- /dev/null +++ b/changelogs/fragments/40424_postgresql_db_not_failed_when_dump_err.yml @@ -0,0 +1,2 @@ +bugfixes: + - postgresql_db - the module fails not always when pg_dump errors occured (https://github.com/ansible/ansible/issues/40424). diff --git a/lib/ansible/modules/database/postgresql/postgresql_db.py b/lib/ansible/modules/database/postgresql/postgresql_db.py index 89cd7c4ea18..db4fbd3ba54 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_db.py +++ b/lib/ansible/modules/database/postgresql/postgresql_db.py @@ -501,9 +501,16 @@ def main(): try: rc, stdout, stderr, cmd = method(module, target, target_opts, db, **kw) if rc != 0: - module.fail_json(msg=stderr, stdout=stdout, rc=rc, cmd=cmd) + module.fail_json(msg='Dump of database %s failed' % db, + stdout=stdout, stderr=stderr, rc=rc, cmd=cmd) + + elif stderr and 'warning' not in str(stderr): + module.fail_json(msg='Dump of database %s failed' % db, + stdout=stdout, stderr=stderr, rc=1, cmd=cmd) + else: - module.exit_json(changed=True, msg=stdout, stderr=stderr, rc=rc, cmd=cmd) + module.exit_json(changed=True, msg='Dump of database %s has been done' % db, + stdout=stdout, stderr=stderr, rc=rc, cmd=cmd) except SQLParseError as e: module.fail_json(msg=to_native(e), exception=traceback.format_exc())