Skip to content

ci: ansible-lint requires collection deps to be installed#240

Merged
richm merged 1 commit intolinux-system-roles:mainfrom
richm:ci-install-deps-for-ansible-lint-collection
Apr 9, 2026
Merged

ci: ansible-lint requires collection deps to be installed#240
richm merged 1 commit intolinux-system-roles:mainfrom
richm:ci-install-deps-for-ansible-lint-collection

Conversation

@richm
Copy link
Copy Markdown
Contributor

@richm richm commented Apr 9, 2026

ansible-lint requires collection deps to be installed

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

Summary by Sourcery

Install required Ansible collections for ansible-lint runs and simplify cleanup handling in the lint helper and tox configuration.

New Features:

  • Automatically install Ansible collection requirements for ansible-lint based on role and test collection-requirements files.

Enhancements:

  • Configure ansible-lint collection tox environment to use the tox work directory as ANSIBLE_COLLECTIONS_PATH.
  • Centralize removal of the .ansible directory in the ansible-lint helper post step instead of duplicating cleanup commands in tox configs.

Tests:

  • Update tox merge fixture to reflect new ansible-lint collection environment settings and centralized .ansible cleanup.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 9, 2026

Reviewer's Guide

Ensure ansible-lint runs with required collection dependencies installed and clean up how the .ansible directory and collection paths are managed in tox environments.

Flow diagram for ansible-lint-collection tox environment execution

flowchart TD
    A["Start testenv:ansible-lint-collection"] --> B["Set basepython=python3"]
    B --> C["Change directory to {toxworkdir}/ansible_collections/{env:LSR_ROLE2COLL_NAMESPACE}/{env:LSR_ROLE2COLL_NAME}"]
    C --> D["Inherit generic testenv environment variables"]
    D --> E["Set ANSIBLE_COLLECTIONS_PATH={toxworkdir}"]
    E --> F["Run ansible-lint-helper.sh pre"]
    F --> G["Run ansible-lint (with collection deps from {toxworkdir})"]
    G --> H["Run ansible-lint-helper.sh post"]
    H --> I["End testenv:ansible-lint-collection"]
Loading

File-Level Changes

Change Details Files
Install required Ansible collections for ansible-lint before running it, excluding the collection under test.
  • Extend the ansible-lint-helper.sh pre() function to build a merged collection-requirements.yml from role and tests locations.
  • Filter out the current collection (LSR_ROLE2COLL_NAMESPACE.LSR_ROLE2COLL_NAME) from the generated requirements using yq.
  • Invoke ansible-galaxy collection install with the generated requirements file into the tox work directory if any requirements are found.
src/tox_lsr/test_scripts/ansible-lint-helper.sh
Move .ansible cleanup into the helper script and remove redundant cleanup from tox configuration and fixtures.
  • Add rm -rf .ansible to the ansible-lint-helper.sh post() function.
  • Remove the explicit bash -c 'rm -rf .ansible' commands from ansible-lint tox environments and their test fixture result.ini.
src/tox_lsr/test_scripts/ansible-lint-helper.sh
src/tox_lsr/config_files/tox-default.ini
tests/fixtures/test_tox_merge_ini/result.ini
Configure ansible-lint collection tox environment to use the tox work directory as the Ansible collections path.
  • Add ANSIBLE_COLLECTIONS_PATH={toxworkdir} to the [testenv:ansible-lint-collection] setenv in tox-default.ini.
  • Mirror the same ANSIBLE_COLLECTIONS_PATH setting in the test fixture result.ini for tox merge tests.
src/tox_lsr/config_files/tox-default.ini
tests/fixtures/test_tox_merge_ini/result.ini

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 - I've left some high level feedback:

  • The yq expression filter(.name != ...) in ansible-lint-helper.sh looks like jq syntax and may not work with common yq versions; consider using a yq-native form like .collections |= map(select(.name != "${LSR_ROLE2COLL_NAMESPACE}.${LSR_ROLE2COLL_NAME}")) or similar and verifying against the intended yq version.
  • When setting ANSIBLE_COLLECTIONS_PATH = {toxworkdir}, consider preserving any existing value (e.g. {env:ANSIBLE_COLLECTIONS_PATH:{toxworkdir}}) if you want to avoid clobbering user or CI-provided paths.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `yq` expression `filter(.name != ...)` in `ansible-lint-helper.sh` looks like jq syntax and may not work with common yq versions; consider using a yq-native form like `.collections |= map(select(.name != "${LSR_ROLE2COLL_NAMESPACE}.${LSR_ROLE2COLL_NAME}"))` or similar and verifying against the intended yq version.
- When setting `ANSIBLE_COLLECTIONS_PATH = {toxworkdir}`, consider preserving any existing value (e.g. `{env:ANSIBLE_COLLECTIONS_PATH:{toxworkdir}}`) if you want to avoid clobbering user or CI-provided paths.

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.

@richm richm force-pushed the ci-install-deps-for-ansible-lint-collection branch from 0656970 to 43a64aa Compare April 9, 2026 17:45
ansible-lint requires collections to be installed in order to find modules referenced.
Install the collections from meta/collection-requirements.yml and
tests/collection-requirements.yml, but do not install fedora.linux_system_roles.

yq code generated by Claude opus-4.6

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
@richm richm force-pushed the ci-install-deps-for-ansible-lint-collection branch from 43a64aa to 4e9a213 Compare April 9, 2026 22:17
@richm richm merged commit 3927c46 into linux-system-roles:main Apr 9, 2026
8 checks passed
@richm richm deleted the ci-install-deps-for-ansible-lint-collection branch April 9, 2026 22:27
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