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

Support ANSIBLE_COLLECTIONS_PATH environment var #3681

Merged
merged 1 commit into from Oct 19, 2022

Conversation

nre-ableton
Copy link
Contributor

@nre-ableton nre-ableton commented Oct 13, 2022

This commit adds supports for reading ANSIBLE_COLLECTIONS_PATH from the environment, in a similar manner to how ANSIBLE_ROLES_PATH is handled.

—---

Fixes #3663

@zhan9san
Copy link
Contributor

Hi @nre-ableton

Thanks for your work.

IMHO, even if you extend the collection paths, the molecule will also install dependencies into ~/.cache/ansible-compat/hash-vaule/, which is an isolated cache path defined in ansible-compat package.

You can find more details in ansible-compat package.

Are you sure the test result is correct?

@nre-ableton
Copy link
Contributor Author

@zhan9san Yes, molecule behaves the same with roles. I wish that molecule had proper offline support, but that is a separate discussion (see ansible/galaxy#2030).

For this to work, prerun: false must also be set in the scenario's molecule.yml file. With that in place, molecule will install collections to ANSIBLE_COLLECTIONS_PATH.

@zhan9san
Copy link
Contributor

zhan9san commented Oct 18, 2022

I wonder if we can introduce an offline mode, no need to install dependencies when run molecule. But instead, we can install them in a cache path on CI server in advance, and let molecule respect this cache path.

---
dependency:
  name: galaxy
  offline: true
  role-file: requirements.yml
  requirements-file: collections.yml

Please allow me to explain it in detail.

Internet access

Currently, there are two kinds of dependencies need to be downloaded from internet when run molecule dependency.

  1. role dependencies which are defined in [project-root-dir]/requirements.yml
  2. dependencies for testing the role in different scenarios, which are defined in role-file: requirements.yml and requirements-file: collections.yml in [project-root-dir]/molecule/[scenario-name]/molecule.yml, referring to molecule.dependency.ansible_galaxy.AnsibleGalaxy

Installation location

Assume the my role name is my_role_2.

For the 1st, the dependencies will be installed by ansible-compat in /Users/jackzhang/.cache/ansible-compat/0afefd/roles and /Users/jackzhang/.cache/ansible-compat/0afefd/collections.

For the 2nd, the dependencies for scenario test will be installed by molecule in /Users/jackzhang/.cache/molecule/my_role_2/default/roles and /Users/jackzhang/.cache/molecule/my_role_2/default/collections

Then, the installed location would be as below.

  1. /Users/jackzhang/.cache/ansible-compat/0afefd/roles
  2. /Users/jackzhang/.cache/ansible-compat/0afefd/collections
  3. /Users/jackzhang/.cache/molecule/my_role_2/default/roles
  4. /Users/jackzhang/.cache/molecule/my_role_2/default/collections
  5. /Users/jackzhang/.cache/molecule/my_role_2/scenario-2/roles
  6. /Users/jackzhang/.cache/molecule/my_role_2/scenario-2/collections
  7. /Users/jackzhang/.cache/molecule/my_role_2/scenario-3/roles
  8. /Users/jackzhang/.cache/molecule/my_role_2/scenario-3/collections
  9. other scenaios, etc.

Unified location

As we can see, there are many different locations. If we install them in one unified location, and ensure molecule respects it, this issue would be solved.

Let me know what you think.

@nre-ableton
Copy link
Contributor Author

@zhan9san I think that this would be a great idea, and I wouldn't mind to implement something like this. Offline mode would be very useful for us. However, I also think that it is a bit beyond the scope of this PR. 😁 I'll go ahead and un-draft this PR, unless you have any strong objections.

@zhan9san
Copy link
Contributor

LGTM.
Go ahead please

This commit adds supports for reading ANSIBLE_COLLECTIONS_PATH from the
environment, in a similar manner to how ANSIBLE_ROLES_PATH is handled.
@nre-ableton nre-ableton marked this pull request as ready for review October 19, 2022 15:14
@nre-ableton nre-ableton requested review from a team as code owners October 19, 2022 15:14
@nre-ableton nre-ableton requested review from ssbarnea, sky-joker, trishnaguha and shatakshiiii and removed request for a team October 19, 2022 15:14
@zhan9san zhan9san merged commit 144bbae into ansible:main Oct 19, 2022
@nre-ableton nre-ableton deleted the nre/main/collections-path branch October 19, 2022 16:45
@nre-ableton
Copy link
Contributor Author

@zhan9san Thanks for the merge!

@ssbarnea ssbarnea added bug and removed feature labels Oct 24, 2022
davedittrich pushed a commit to davedittrich/molecule that referenced this pull request Oct 24, 2022
This commit adds supports for reading ANSIBLE_COLLECTIONS_PATH from the
environment, in a similar manner to how ANSIBLE_ROLES_PATH is handled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Molecule doesn't respect ANSIBLE_ROLES_PATH or ANSIBLE_COLLECTIONS_PATH
3 participants