From fc54ae9227cf0a54962a60539b42dc4db71d2cf4 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Thu, 5 Dec 2019 07:28:10 +1100 Subject: [PATCH] dnf: don't return fail_json['msg'] as list (#65302) Although it's not enforced that fail_json['msg'] should be a string [1], I think it is pretty strongly implied. In this case the failure_response['msg'] is sent through as the fail_json['msg'], and the trailing commas here turn it into a tuple. It's not clear if this is a typo or intended, but it does cause problems for callbacks that expect this as a string (e.g. [2]). Since there seems no point to having these values as a tuple, remove the trailing commas so they return a string as per everywhere else. [1] https://github.com/ansible/ansible/blob/4c589661c2add45023f2bff9203e0c4e11efe5f6/lib/ansible/module_utils/basic.py#L2078 [2] https://review.opendev.org/#/c/696081 --- changelogs/fragments/65302-dnf-msg-return.yml | 3 +++ lib/ansible/modules/packaging/os/dnf.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/65302-dnf-msg-return.yml diff --git a/changelogs/fragments/65302-dnf-msg-return.yml b/changelogs/fragments/65302-dnf-msg-return.yml new file mode 100644 index 00000000000000..9202a3dfe270d9 --- /dev/null +++ b/changelogs/fragments/65302-dnf-msg-return.yml @@ -0,0 +1,3 @@ +bugfixes: + - dnf module - Ensure the modules exit_json['msg'] response is + always string, not sometimes a tuple. diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index cf796bf688664f..c548452eb6c46a 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -1165,7 +1165,7 @@ def ensure(self): else: response['changed'] = True if failure_response['failures']: - failure_response['msg'] = 'Failed to install some of the specified packages', + failure_response['msg'] = 'Failed to install some of the specified packages' self.module.fail_json(**failure_response) if self.module.check_mode: response['msg'] = "Check mode: No changes made, but would have if not in check mode" @@ -1195,7 +1195,7 @@ def ensure(self): response['results'].append("Removed: {0}".format(package)) if failure_response['failures']: - failure_response['msg'] = 'Failed to install some of the specified packages', + failure_response['msg'] = 'Failed to install some of the specified packages' self.module.exit_json(**response) self.module.exit_json(**response) except dnf.exceptions.DepsolveError as e: