community.general.collection_version (6.6.8) — 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:==6.6.8


Add to requirements.yml

  collections:
    - name: community.general
      version: 6.6.8

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 C(none) for non-existing collections and C(*) 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 I(result_not_found) and I(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 C(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, C(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, C(*) 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 I(result_not_found).
    By default, this is C(none).
  - If a collection can be found, but the version not identified, it will return the
    value provided in I(result_no_version). By default, this is C(*). This can happen
    for collections installed from git which do not have a version number in C(galaxy.yml).
  elements: str
  type: list