From c9819b57b3991ab94e490f73846667e23240af21 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Thu, 25 Sep 2025 20:46:15 +0200 Subject: [PATCH] [PR #10857/68684a7a backport][stable-9] github_deploy_key: make sure variable exists before use (#10858) github_deploy_key: make sure variable exists before use (#10857) Make sure variable exists before use. (cherry picked from commit 68684a7a4c1432b58dd7dd6ab4e0dff388f5e34b) Co-authored-by: Felix Fontein --- changelogs/fragments/10857-github_deploy_key-err.yml | 2 ++ plugins/modules/github_deploy_key.py | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 changelogs/fragments/10857-github_deploy_key-err.yml diff --git a/changelogs/fragments/10857-github_deploy_key-err.yml b/changelogs/fragments/10857-github_deploy_key-err.yml new file mode 100644 index 0000000000..58bac31c5e --- /dev/null +++ b/changelogs/fragments/10857-github_deploy_key-err.yml @@ -0,0 +1,2 @@ +bugfixes: + - "github_deploy_key - fix bug during error handling if no body was present in the result (https://github.com/ansible-collections/community.general/issues/10853, https://github.com/ansible-collections/community.general/pull/10857)." diff --git a/plugins/modules/github_deploy_key.py b/plugins/modules/github_deploy_key.py index 2e5f9125ad..3eb4d777a5 100644 --- a/plugins/modules/github_deploy_key.py +++ b/plugins/modules/github_deploy_key.py @@ -284,6 +284,8 @@ class GithubDeployKey(object): body = info.get('body') if body: err = self.module.from_json(body)['message'] + else: + err = None if status_code == 401: self.module.fail_json(msg="Failed to connect to {0} due to invalid credentials".format(self.github_url), http_status_code=status_code, error=err)