community.general.collection_version (8.5.0) — lookup

Retrieves the version of an installed collection

| "added in version" 4.0.0 of community.general"

Authors: Felix Fontein (@felixfontein)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

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 V(none) for non-existing collections and V(*) 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 C(galaxy.yml). This behavior can be adjusted by providing other values with O(result_not_found) and O(result_no_version).

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Check version of community.general
  ansible.builtin.debug:
    msg: "community.general version {{ lookup('community.general.collection_version', 'community.general') }}"

Inputs

    
_terms:
    description:
    - The collections to look for.
    - For example V(community.general).
    elements: str
    required: true
    type: list

result_not_found:
    default: null
    description:
    - The value to return when the collection could not be found.
    - By default, V(none) is returned.
    type: string

result_no_version:
    default: '*'
    description:
    - 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 C(galaxy.yml).
    - By default, V(*) is returned.
    type: string

Outputs

_raw:
  description:
  - The version number of the collections listed as input.
  - If a collection can not be found, it will return the value provided in O(result_not_found).
    By default, this is V(none).
  - If a collection can be found, but the version not identified, it will return the
    value provided in O(result_no_version). By default, this is V(*). This can happen
    for collections installed from git which do not have a version number in V(galaxy.yml).
  elements: str
  type: list