Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update default globbing pattern for collection matching #4177

Closed
wants to merge 2 commits into from

Conversation

trfore
Copy link
Contributor

@trfore trfore commented May 1, 2024

This update:

  • restricts the glob matching for molecule test
  • updates the default value for MOLECULE_GLOB="**/molecule/*/molecule.yml"

This allows:

  • users to call molecule from the collection folder and molecule will use the collection name in the ephemeral cache, .cache/molecule/COLLECTION_NAME.

WARNING:
If working within the ANSIBLE_COLLECTIONS_PATH directory, e.g. ~/.ansible/collections/ansible_collections/COLLECTION_NAME (default), using the new default setting MOLECULE_GLOB="**/molecule/*/molecule.yml" will globber clobber and delete the collection folder. This occurs in the presence of a galaxy.yml - as molecule calls ansible_compat.runtime(isolate=False) and will run ansible_compat.runtime.prepare_environment. However, if you delete the galaxy.yml OR chdir into COLLECTION_NAME/extensions and it will not delete the collection folder.

Currently (v24.2.1):
Calling molecule list will find all molecule.yml files within a collection folder that use a nested dir structure, i.e
COLLECTION_NAME/extensions/molecule/SCENARIO_NAME/molecule.yml. As it calls base.get_configs and sets the argument glob=str"**/molecule/*/molecule.yml".

This does not occur with molecule test, as it calls to base.execute_cmdline_scenarios and uses
MOLECULE_GLOB = os.environ.get("MOLECULE_GLOB", "molecule/*/molecule.yml").

Attempting to set an env var MOLECULE_GLOB="**/molecule/*/molecule.yml" will fail, as test attempts to insert the scenario name into every wild-card. But, this fuzzy matching acts as a safe guard against deleting the collection when working within the same ANSIBLE_COLLECTIONS_PATH directory:

$ MOLECULE_GLOB="**/molecule/*/molecule.yml" molecule test
CRITICAL 'defaultdefault/molecule/default/molecule.yml' glob failed.

Copy link

github-actions bot commented May 1, 2024

Label error. Requires exactly 1 of: bug, enhancement, major, minor, patch, skip-changelog. Found:

@trfore
Copy link
Contributor Author

trfore commented May 1, 2024

So I was curious why molecule list is collection aware and all the other commands are not. The current work-around for making molecule collection aware is to use one of the following approaches:

$ MOLECULE_GLOB="./extensions/molecule/*/molecule.yml" molecule test
$ MOLECULE_GLOB="$(pwd)/extensions/molecule/*/molecule.yml" molecule test

@trfore trfore closed this by deleting the head repository Sep 4, 2024
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.

1 participant