Skip to content

Commit 79b3521

Browse files
[PR #10011/c2480730 backport][stable-10] fix: github_deploy_key check key exists on 422 (#10036)
fix: github_deploy_key check key exists on 422 (#10011) * fix: github_deploy_key check key exists on 422 If we get a 422 response code as we add a key, check if it's because the key already exists or for another reason. fixes: #6718 * chore: add changelog 10011-github_deploy_key-check-key-present * chore: fix changelog fragment * chore: fix changelog fragment * Update changelog fragment. --------- Co-authored-by: Felix Fontein <[email protected]> (cherry picked from commit c248073) Co-authored-by: Alex Garel <[email protected]>
1 parent 7aae8a9 commit 79b3521

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- "github_deploy_key - check that key really exists on 422 to avoid masking other errors (https://github.com/ansible-collections/community.general/issues/6718, https://github.com/ansible-collections/community.general/pull/10011)."

plugins/modules/github_deploy_key.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,12 @@ def add_new_key(self):
259259
key_id = response_body["id"]
260260
self.module.exit_json(changed=True, msg="Deploy key successfully added", id=key_id)
261261
elif status_code == 422:
262-
self.module.exit_json(changed=False, msg="Deploy key already exists")
262+
# there might be multiple reasons for a 422
263+
# so we must check if the reason is that the key already exists
264+
if self.get_existing_key():
265+
self.module.exit_json(changed=False, msg="Deploy key already exists")
266+
else:
267+
self.handle_error(method="POST", info=info)
263268
else:
264269
self.handle_error(method="POST", info=info)
265270

0 commit comments

Comments
 (0)