community.general.gitlab_group_variable (2.5.9) — module

Creates, updates, or deletes GitLab groups variables

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

Authors: Florent Madiot (@scodeman)

Install collection

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


Add to requirements.yml

  collections:
    - name: community.general
      version: 2.5.9

Description

Creates a group variable if it does not exist.

When a group variable does exist, its value will be updated when the values are different.

Variables which are untouched in the playbook, but are not untouched in the GitLab group, they stay untouched (I(purge) is C(false)) or will be deleted (I(purge) is C(true)).


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set or update some CI/CD variables
  community.general.gitlab_group_variable:
    api_url: https://gitlab.com
    api_token: secret_access_token
    group: scodeman/testgroup/
    purge: false
    vars:
      ACCESS_KEY_ID: abc123
      SECRET_ACCESS_KEY: 321cba
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set or update some CI/CD variables
  community.general.gitlab_group_variable:
    api_url: https://gitlab.com
    api_token: secret_access_token
    group: scodeman/testgroup/
    purge: false
    vars:
      ACCESS_KEY_ID: abc123
      SECRET_ACCESS_KEY:
        value: 3214cbad
        masked: true
        protected: true
        variable_type: env_var
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete one variable
  community.general.gitlab_group_variable:
    api_url: https://gitlab.com
    api_token: secret_access_token
    group: scodeman/testgroup/
    state: absent
    vars:
      ACCESS_KEY_ID: abc123

Inputs

    
vars:
    default: {}
    description:
    - When the list element is a simple key-value pair, set masked and protected to false.
    - When the list element is a dict with the keys I(value), I(masked) and I(protected),
      the user can have full control about whether a value should be masked, protected
      or both.
    - Support for protected values requires GitLab >= 9.3.
    - Support for masked values requires GitLab >= 11.10.
    - A I(value) must be a string or a number.
    - Field I(variable_type) must be a string with either C(env_var), which is the default,
      or C(file).
    - When a value is masked, it must be in Base64 and have a length of at least 8 characters.
      See GitLab documentation on acceptable values for a masked variable (U(https://docs.gitlab.com/ce/ci/variables/#masked-variables)).
    type: dict

group:
    description:
    - The path and name of the group.
    required: true
    type: str

purge:
    default: false
    description:
    - When set to C(true), delete all variables which are not untouched in the task.
    type: bool

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Create or delete group variable.
    type: str

api_url:
    description:
    - The resolvable endpoint for the API
    type: str

api_token:
    description:
    - GitLab access token with API permissions.
    required: true
    type: str

api_password:
    description:
    - The password to use for authentication against the API
    type: str

api_username:
    description:
    - The username to use for authentication against the API
    type: str

validate_certs:
    default: true
    description:
    - Whether or not to validate SSL certs when supplying a https endpoint.
    type: bool

Outputs

group_variable:
  contains:
    added:
      description: A list of variables which were created.
      returned: always
      sample: '[''ACCESS_KEY_ID'', ''SECRET_ACCESS_KEY'']'
      type: list
    removed:
      description: A list of variables which were deleted.
      returned: always
      sample: '[''ACCESS_KEY_ID'', ''SECRET_ACCESS_KEY'']'
      type: list
    untouched:
      description: A list of variables which exist.
      returned: always
      sample: '[''ACCESS_KEY_ID'', ''SECRET_ACCESS_KEY'']'
      type: list
    updated:
      description: A list of variables whose values were changed.
      returned: always
      sample: '[''ACCESS_KEY_ID'', ''SECRET_ACCESS_KEY'']'
      type: list
  description: Four lists of the variablenames which were added, updated, removed
    or exist.
  returned: always
  type: dict