Skip to content

Conversation

cidrblock
Copy link
Contributor

@cidrblock cidrblock commented Aug 13, 2025

Depends on: ansible/ansible-compat#516

Problem

When ansible-lint runs on collections for the first time, it fails to discover plugins from collections installed by ansible-compat during prepare_environment(). This manifests as "No test named 'ansible.utils.unspecified'" errors and other plugin discovery failures that work correctly on subsequent runs.

Root Cause

The issue occurs because Ansible's plugin loader is initialized too early with incomplete collection paths, before prepare_environment() has a chance to install dependencies from requirements.yml and galaxy.yml files.

This particularly affects Templar usage since it internally relies on Ansible's collection loader for template rendering and plugin discovery. When the plugin loader captures incomplete collection paths early, Templar fails to find collections that were installed during prepare_environment().

Solution

This PR adds a call to app.runtime.enable_plugin_loader() after prepare_environment() completes in get_app(). This ensures that:

  1. Collections are fully installed from requirements and galaxy files first
  2. The plugin loader is initialized with complete collection paths
  3. Templar and other components can discover plugins from newly installed collections on the first run

Changes Made

  • app.py: Added app.runtime.enable_plugin_loader() call after prepare_environment()

Dependencies

This change requires the corresponding plugin loader gating mechanism implemented in ansible-compat PR #516, which provides:

  • Runtime.enable_plugin_loader() method for explicit initialization
  • Gated access to prevent early plugin loader initialization
  • Enhanced state management for test isolation

Impact

  • First-run collection discovery now works reliably
  • Eliminates "works on second run" behavior
  • Template rendering can access newly installed collections
  • Plugin discovery errors are resolved
  • No breaking changes to existing functionality
  • Avoid loading collection loader if not needed (e.g. molecule)

Testing

Tested with collections that have requirements.yml and galaxy.yml dependencies. The plugin discovery now works correctly on the first run instead of requiring a second execution.

Fixes first-run collection discovery issue by calling enable_plugin_loader()
after prepare_environment() has installed collections from requirements.yml
and galaxy.yml files.

This ensures that Ansible's plugin loader is initialized with complete
collection paths, allowing Templar and other components to properly discover
plugins from newly installed collections on the first run.

Related to: ansible/ansible-compat#516
@cidrblock cidrblock force-pushed the fix/enable-plugin-loader-after-prepare branch from 7733b07 to 0d91411 Compare August 13, 2025 23:12
The SPDX license list has been updated with new license identifiers.
This commit includes the automatically generated updates to maintain
compatibility with the latest SPDX license database.
@cidrblock cidrblock force-pushed the fix/enable-plugin-loader-after-prepare branch from c9eb031 to 30ea0a9 Compare August 13, 2025 23:50
@cidrblock cidrblock merged commit 1080d91 into ansible:main Aug 14, 2025
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants