Skip to content

github_deploy_key: do not delete the key with state=absent in check mode - #13132

Merged
felixfontein merged 2 commits into
ansible-collections:mainfrom
sarankumar1325:github-deploy-key-check-mode-absent
Oct 30, 2026
Merged

felixfontein merged 2 commits into
ansible-collections:mainfrom
sarankumar1325:github-deploy-key-check-mode-absent

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor
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

@ansibullbot

Copy link
Copy Markdown
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module new_contributor Help guide this first time contributor new_plugin New plugin plugins plugin (any type) tests tests unit tests/unit labels Oct 30, 2026
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-12 Automatically create a backport for the stable-12 branch backport-13 Automatically create a backport for the stable-13 branch labels Oct 30, 2026

@felixfontein felixfontein left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contriibution!

Comment thread plugins/modules/github_deploy_key.py Resolved
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.
@felixfontein
felixfontein merged commit f7b4249 into ansible-collections:main Oct 30, 2026
138 checks passed
@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Oct 30, 2026
@patchback

patchback Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Backport to stable-13: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-13/f7b4249fffef6563ada9be3de076ef0a095bc3b2/pr-13132

Backported as #13160

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein

Copy link
Copy Markdown
Collaborator

@sarankumar1325 thanks for your contribution!

@patchback

patchback Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Backport to stable-12: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-12/f7b4249fffef6563ada9be3de076ef0a095bc3b2/pr-13132

Backported as #13162

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@patchback

patchback Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Backport to stable-11: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-11/f7b4249fffef6563ada9be3de076ef0a095bc3b2/pr-13132

Backported as #13161

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

felixfontein pushed a commit that referenced this pull request Oct 30, 2026
…lete the key with state=absent in check mode (#13160)

github_deploy_key: do not delete the key with state=absent in check mode (#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)

Co-authored-by: sarankumar <120080287+sarankumar1325@users.noreply.github.com>
felixfontein added a commit that referenced this pull request Oct 30, 2026
…lete the key with state=absent in check mode (#13162)

* github_deploy_key: do not delete the key with state=absent in check mode (#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)

* Remove new unit tests.

---------

Co-authored-by: sarankumar <120080287+sarankumar1325@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
felixfontein added a commit that referenced this pull request Oct 30, 2026
…lete the key with state=absent in check mode (#13161)

* github_deploy_key: do not delete the key with state=absent in check mode (#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)

* Remove Python 3.7+ syntax.

* Add boilerplate.

* Remove new unit tests.

---------

Co-authored-by: sarankumar <120080287+sarankumar1325@users.noreply.github.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-11 Automatically create a backport for the stable-10 branch backport-12 Automatically create a backport for the stable-12 branch backport-13 Automatically create a backport for the stable-13 branch bug This issue/PR relates to a bug module module new_contributor Help guide this first time contributor new_plugin New plugin plugins plugin (any type) tests tests unit tests/unit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Module github_deploy_key removes the key in check mode

3 participants