community.general.collection_version – Retrieves the version of an installed collection

Note

This plugin is part of the community.general collection (version 4.2.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.collection_version.

New in version 4.0.0: of community.general

Synopsis

  • This lookup allows to query the version of an installed collection, and to determine whether a collection is installed at all.

  • By default it returns none for non-existing collections and * for collections without a version number. The latter should only happen in development environments, or when installing a collection from git which has no version in its galaxy.yml. This behavior can be adjusted by providing other values with result_not_found and result_no_version.

Parameters

Parameter Choices/Defaults Configuration Comments
_terms
list / elements=string / required
The collections to look for.
For example community.general.
result_no_version
string
Default:
"*"
The value to return when the collection has no version number.
This can happen for collections installed from git which do not have a version number in galaxy.yml.
By default, * is returned.
result_not_found
string
The value to return when the collection could not be found.
By default, none is returned.

Examples

- name: Check version of community.general
  ansible.builtin.debug:
    msg: "community.general version {{ lookup('community.general.collection_version', 'community.general') }}"

Return Values

Common return values are documented here, the following are the fields unique to this lookup:

Key Returned Description
_raw
list / elements=string
success
The version number of the collections listed as input.
If a collection can not be found, it will return the value provided in result_not_found. By default, this is none.
If a collection can be found, but the version not identified, it will return the value provided in result_no_version. By default, this is *. This can happen for collections installed from git which do not have a version number in galaxy.yml.



Authors

  • Felix Fontein (@felixfontein)