Skip to content

refactor: support Ansible 2.19#794

Merged
richm merged 1 commit into
linux-system-roles:mainfrom
richm:fix-ansible-2.19
Jul 2, 2025
Merged

refactor: support Ansible 2.19#794
richm merged 1 commit into
linux-system-roles:mainfrom
richm:fix-ansible-2.19

Conversation

@richm
Copy link
Copy Markdown
Contributor

@richm richm commented Jun 26, 2025

The big problem was trying to use vars with import_playbook.

We do not need to use import_playbook when include_tasks will
work. Perhaps the original author of these tests thought that
the play roles keyword was the only way to invoke roles, so
that had to be "called" using an import_playbook?

Use include_tasks instead of import_playbook, and move some
of those "tasks" playbooks to be tasks files in tests/tasks.

Use include_role instead of import_role.

Do not set variables using set_fact if they have already been
set at the appropriate scope using vars.

"Modernize" the code somewhat.

Improve formatting.

Work around an Ansible bug ansible/ansible#85394

Signed-off-by: Rich Megginson rmeggins@redhat.com

Summary by Sourcery

Refactor the test suite to support Ansible 2.19 by replacing deprecated import_* directives with include_tasks/include_role, removing redundant set_fact usage, reorganizing task files, and filtering expected plugin warnings to work around Ansible issue #85394.

Bug Fixes:

  • Adjust assertion logic to filter out known plugin-load warnings, working around Ansible bug #85394

Enhancements:

  • Replace import_playbook calls with include_tasks throughout test playbooks
  • Replace import_role usage with include_role in all tests
  • Remove unnecessary set_fact statements and consolidate variable definitions at the play or role level
  • Move standalone playbook fragments into dedicated files under tests/tasks and update references accordingly

Tests:

  • Revise test playbooks to leverage include_tasks/include_role patterns and updated task structure

@richm richm requested a review from liangwen12year as a code owner June 26, 2025 15:44
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 26, 2025

Reviewer's Guide

This PR refactors the existing test playbooks to fully support Ansible 2.19 by replacing deprecated import_playbook/import_role patterns with include_tasks/include_role calls, reorganizing task playbooks into a dedicated tasks directory, removing redundant set_fact usage for already-declared vars, and adding a targeted workaround for a known Ansible warnings bug.

File-Level Changes

Change Details Files
Replace import_playbook calls with include_tasks
  • Swapped all import_playbook directives to include_tasks
  • Inlined per-play vars under each include_tasks call
  • Removed obsolete run_tasks playbooks
tests/playbooks/*.yml
Replace import_role calls with include_role
  • Converted import_role to include_role blocks
  • Moved role vars directly under include_role
tests/playbooks/*.yml
Reorganize standalone playbooks into tasks directory
  • Deleted down_profile.yml, remove_profile.yml and run_tasks.yml under playbooks
  • Introduced new tasks under tests/tasks (down_profile.yml, remove_profile.yml, down_profile+delete_interface.yml)
  • Updated references in playbooks to point at tests/tasks
tests/playbooks/down_profile.yml
tests/playbooks/remove_profile.yml
tests/playbooks/run_tasks.yml
tests/tasks/down_profile.yml
tests/tasks/remove_profile.yml
tests/tasks/down_profile+delete_interface.yml
Remove redundant set_fact usages
  • Dropped set_fact tasks for variables already defined in vars
  • Cleaned up tests in bridge, ethernet, IPv6, route tables
tests/playbooks/tests_bridge.yml
tests/playbooks/tests_ethernet.yml
tests/playbooks/tests_ipv6_disabled.yml
tests/playbooks/tests_bridge_cloned_mac.yml
Add workaround for Ansible bug #85394 in warning assertions
  • Extended warning assertions to filter out known module_warning
  • Introduced module_warning var with regex match
  • Applied change in default tests and stderr assertion task
tests/tasks/assert_output_in_stderr_without_warnings.yml
tests/tests_default.yml

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

Copy link
Copy Markdown

@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 @richm - I've reviewed your changes - here's some feedback:

  • The repeated cleanup and assertion include_tasks patterns across test playbooks could be abstracted into a shared task list or role to reduce duplication.
  • The bug workaround in assert_output_in_stderr_without_warnings.yml relies on the exact plugin error text; consider using a regex or more flexible match to guard against upstream message changes.
  • Multiple #FIXME annotations indicate missing assertions (e.g., verifying interface down/up); please address these or file follow-up issues to avoid gaps in test coverage.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The repeated cleanup and assertion include_tasks patterns across test playbooks could be abstracted into a shared task list or role to reduce duplication.
- The bug workaround in assert_output_in_stderr_without_warnings.yml relies on the exact plugin error text; consider using a regex or more flexible match to guard against upstream message changes.
- Multiple #FIXME annotations indicate missing assertions (e.g., verifying interface down/up); please address these or file follow-up issues to avoid gaps in test coverage.

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

codecov Bot commented Jun 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.25%. Comparing base (1b57520) to head (0cd8c46).
Report is 27 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #794      +/-   ##
==========================================
+ Coverage   43.11%   43.25%   +0.13%     
==========================================
  Files          12       12              
  Lines        3124     3121       -3     
==========================================
+ Hits         1347     1350       +3     
+ Misses       1777     1771       -6     

☔ 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 richm force-pushed the fix-ansible-2.19 branch from b6b1530 to 53f66b4 Compare June 26, 2025 16:22
@richm
Copy link
Copy Markdown
Contributor Author

richm commented Jun 26, 2025

[citest]

@richm
Copy link
Copy Markdown
Contributor Author

richm commented Jun 26, 2025

[citest]

The big problem was trying to use `vars` with `import_playbook`.

We do not need to use `import_playbook` when `include_tasks` will
work.  Perhaps the original author of these tests thought that
the play `roles` keyword was the only way to invoke roles, so
that had to be "called" using an `import_playbook`?

Use `include_tasks` instead of `import_playbook`, and move some
of those "tasks" playbooks to be tasks files in tests/tasks.

Use `include_role` instead of `import_role`.

Do not set variables using `set_fact` if they have already been
set at the appropriate scope using `vars`.

"Modernize" the code somewhat.

Improve formatting.

Work around an Ansible bug ansible/ansible#85394

Fix ansible-lint and ansible-test issues related newer versions of
those tools.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
@richm richm force-pushed the fix-ansible-2.19 branch from 7854e60 to 0cd8c46 Compare June 26, 2025 23:03
@richm
Copy link
Copy Markdown
Contributor Author

richm commented Jun 26, 2025

[citest]

@richm richm merged commit 65e7456 into linux-system-roles:main Jul 2, 2025
36 of 38 checks passed
@richm richm deleted the fix-ansible-2.19 branch July 2, 2025 20:42
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