Skip to content

[PR #13132/f7b4249f backport][stable-11] github_deploy_key: do not delete the key with state=absent in check mode - #13161

Merged
felixfontein merged 4 commits into
stable-11from
patchback/backports/stable-11/f7b4249fffef6563ada9be3de076ef0a095bc3b2/pr-13132
Oct 30, 2026
Merged

felixfontein merged 4 commits into
stable-11from
patchback/backports/stable-11/f7b4249fffef6563ada9be3de076ef0a095bc3b2/pr-13132

Conversation

@patchback

@patchback patchback Bot commented Oct 30, 2026

Copy link
Copy Markdown

This is a backport of PR #13132 as merged into main (f7b4249).

SUMMARY

github_deploy_key with state: absent deleted an existing deploy key even in check mode. The check-mode block in main() only handled state: present, so for state: absent execution fell through to remove_existing_key() and sent the DELETE request.

In check mode with state: absent, the module now only looks up the key and reports changed: true if it exists (with its id) or changed: false if it doesn't, without calling the API's DELETE endpoint.

Fixes #12348

Assisted-by: Grok Bot (AI assistant); I reviewed and tested the change.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

github_deploy_key

ADDITIONAL INFORMATION

Added tests/unit/plugins/modules/test_github_deploy_key.py (mocks fetch_url):

  • check mode + absent + existing key: changed=True, only a GET is sent (this test fails on main because a DELETE is issued)
  • check mode + absent + missing key: changed=False, no DELETE
  • normal mode + absent + existing key: still deletes /keys/<id>
ansible-test units --python 3.13 tests/unit/plugins/modules/test_github_deploy_key.py  -> 3 passed
ansible-test sanity --test compile/pep8/validate-modules (touched files) -> OK
ruff check / ruff format --check (ruff-modules.toml / ruff-plugins.toml) -> OK

…ode (#13132)

* github_deploy_key: do not delete the key with state=absent in check mode

Fixes #12348.

Assisted-by: Grok Bot

* github_deploy_key: only return id in check mode when the key exists

Match the non-check-mode result for state=absent: return id and the
'Deploy key successfully deleted' message only when a key would be
removed, and 'Deploy key does not exist' otherwise. Add the PR link to
the changelog fragment.

(cherry picked from commit f7b4249)
@ansibullbot

Copy link
Copy Markdown
Collaborator

@ansibullbot ansibullbot added backport bug This issue/PR relates to a bug module module new_contributor Help guide this first time contributor plugins plugin (any type) tests tests unit tests/unit labels Oct 30, 2026
@felixfontein
felixfontein merged commit 947bd45 into stable-11 Oct 30, 2026
114 checks passed
@felixfontein
felixfontein deleted the patchback/backports/stable-11/f7b4249fffef6563ada9be3de076ef0a095bc3b2/pr-13132 branch October 30, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport bug This issue/PR relates to a bug module module new_contributor Help guide this first time contributor plugins plugin (any type) tests tests unit tests/unit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants