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

Add collection_version lookup #3633

Merged

Conversation

felixfontein
Copy link
Collaborator

SUMMARY

This lookup allows to query the version of a collection that's installed and loaded by the currently running Ansible version.

This can be useful in roles or playbooks that have to support a larger range of collection (or Ansible community package) versions, where backwards incompatible changes have been made, or where some operations can be optimized with new plugins/modules that are not available in all supported versions.

ISSUE TYPE
  • New Plugin Pull Request
COMPONENT NAME

collection_version

@ansibullbot ansibullbot added integration tests/integration lookup lookup plugin needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_plugin New plugin plugins plugin (any type) tests tests and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Oct 29, 2021
@felixfontein felixfontein added the check-before-release PR will be looked at again shortly before release and merged if possible. label Oct 30, 2021
plugins/lookup/collection_version.py Show resolved Hide resolved
plugins/lookup/collection_version.py Outdated Show resolved Hide resolved
else:
data = {}
galaxy_path = os.path.join(path, 'galaxy.yml')
galaxy_alt_path = os.path.join(path, 'galaxy.yaml')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, galaxy.yaml was never a valid name for the collection metadata file (and git grep through ansible/ansible seems to confirm my suspicions). Maybe we can remove this line and simplify the code a bit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true for ansible-core 2.12 and Ansible 2.9, but ansible-base 2.10 and ansible-core 2.11 did support galaxy.yaml. Support was removed in ansible/ansible@595413d (see the changes in lib/ansible/galaxy/collection/__init__.py which are hidden by default). I'll add a comment to document that though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented in 1169b5a.

I can also remove this, or make this code only execute for 2.10 and 2.11. What do you think?

plugins/lookup/collection_version.py Outdated Show resolved Hide resolved
Copy link
Contributor

@briantist briantist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this! As discussed in IRC I hope this would make its way to core too: ansible/community#631 (comment)

plugins/lookup/collection_version.py Outdated Show resolved Hide resolved
felixfontein and others added 2 commits October 30, 2021 17:40
Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>
@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Oct 30, 2021
@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Oct 30, 2021
@felixfontein felixfontein merged commit 5b10f82 into ansible-collections:main Nov 1, 2021
@felixfontein
Copy link
Collaborator Author

@rndmh3ro @tadeboro @briantist @agaffney thanks for reviewing and discussing this (resp. earlier versions)!

@felixfontein felixfontein deleted the check-collection branch November 1, 2021 18:02
@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Nov 3, 2021
JonEllis pushed a commit to JonEllis/community.general that referenced this pull request Nov 16, 2021
* Add collection_verison lookup plugin.

* Document ansible-base 2.10 and ansible-core 2.11 special case.

* Add default for result_not_found.

* Simplify not existing test.

* Move metadata loading to function.

* Update plugins/lookup/collection_version.py

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>

* Extend tests.

* Fix tests for ansible-core < 2.12.

Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has_issue integration tests/integration lookup lookup plugin new_plugin New plugin plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants