Skip to content

Conversation

@richm
Copy link
Contributor

@richm richm commented Jan 12, 2026

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

Summary by Sourcery

Enhancements:

  • Route collected warning messages through the module's warn() method when available, falling back to returning them in the warnings field for older Ansible versions.

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>
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 12, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts 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_kwargs

sequenceDiagram
    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
Loading

Updated class diagram for warning handling in network_connections module

classDiagram
    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
Loading

File-Level Changes

Change Details Files
Refactor warning handling to prefer the module.warn method over returning a warnings key, with fallback for older Ansible.
  • Change acquisition of existing warning messages from reading to popping the warnings entry from kwargs so it is not passed back unchanged.
  • Accumulate runtime and traceback warnings into a local warning list as before.
  • If the module object exposes a callable warn attribute, iterate over all warning messages and emit them via module.warn instead of returning them in the result.
  • If module.warn is not available, continue to return warnings via the warnings entry in kwargs to remain compatible with older Ansible.
  • Preserve existing behavior for debug logging, stderr construction, and _invocation metadata.
library/network_connections.py

Possibly linked issues

  • #Passing 'warnings' to 'exit_json' or 'fail_json' is deprecated warning with Ansible 2.20: PR updates network_connections module to call module.warn instead of returning warnings, resolving the 2.20 deprecation warning.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@richm
Copy link
Contributor Author

richm commented Jan 12, 2026

fixes #830

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.18%. Comparing base (1b57520) to head (1a2b126).
⚠️ Report is 62 commits behind head on main.

Files with missing lines Patch % Lines
library/network_connections.py 0.00% 5 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@richm
Copy link
Contributor Author

richm commented Jan 12, 2026

[citest]

@richm richm merged commit 1c56680 into linux-system-roles:main Jan 13, 2026
35 of 42 checks passed
@richm richm deleted the fix-warnings-deprecated branch January 13, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant