refactor: use the warn module method on newer Ansible#835
Merged
richm merged 1 commit intolinux-system-roles:mainfrom Jan 13, 2026
Merged
refactor: use the warn module method on newer Ansible#835richm merged 1 commit intolinux-system-roles:mainfrom
richm merged 1 commit intolinux-system-roles:mainfrom
Conversation
Starting with Ansible 2.20, modules should not return the `warnings` key in the module return. Instead, modules should use the `warn` method to specify the warnings. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts how module warnings are handled to use Ansible’s module.warn API when available, while preserving legacy behavior for older Ansible versions. Sequence diagram for updated warning handling in _complete_kwargssequenceDiagram
participant Caller
participant NetworkConnections
participant AnsibleModule
Caller->>NetworkConnections: _complete_kwargs(connections, kwargs, traceback_msg, fail)
NetworkConnections->>NetworkConnections: collect warning_logs from _run_results
alt traceback_msg is not None
NetworkConnections->>NetworkConnections: warning_logs.append(traceback_msg)
end
NetworkConnections->>AnsibleModule: getattr(module, warn, None)
alt module.warn is callable
loop for each msg in warning_logs
NetworkConnections->>AnsibleModule: warn(msg)
end
Note right of NetworkConnections: warnings are emitted via module.warn
else module.warn not available
NetworkConnections->>NetworkConnections: kwargs[warnings] = warning_logs
Note right of NetworkConnections: legacy behavior using warnings in return
end
NetworkConnections->>NetworkConnections: kwargs[stderr] = joined debug logs
NetworkConnections->>NetworkConnections: kwargs[_invocation] = module.params
NetworkConnections-->>Caller: kwargs
Updated class diagram for warning handling in network_connections moduleclassDiagram
class NetworkConnections {
+module
+_run_results
+_complete_kwargs(connections, kwargs, traceback_msg, fail)
+_complete_kwargs_loglines(rr, connections, idx)
}
class AnsibleModule {
+params
+warn(msg)
}
NetworkConnections --> AnsibleModule : uses
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
Author
|
fixes #830 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #835 +/- ##
==========================================
+ Coverage 43.11% 43.18% +0.06%
==========================================
Files 12 12
Lines 3124 3126 +2
==========================================
+ Hits 1347 1350 +3
+ Misses 1777 1776 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
[citest] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Starting with Ansible 2.20, modules should not return the
warningskey in the modulereturn. Instead, modules should use the
warnmethod to specify the warnings.Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
Enhancements: