community.general.gitlab_runner (8.5.0) — module

Create, modify and delete GitLab Runners

Authors: Samy Coenen (@SamyCoenen), Guillaume Martinez (@Lunik)

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

Register, update and delete runners with the GitLab API.

All operations are performed using the GitLab API v4.

For details, consult the full API documentation at U(https://docs.gitlab.com/ee/api/runners.html).

A valid private API token is required for all operations. You can create as many tokens as you like using the GitLab web interface at U(https://$GITLAB_URL/profile/personal_access_tokens).

A valid registration token is required for registering a new runner. To create shared runners, you need to ask your administrator to give you this token. It can be found at U(https://$GITLAB_URL/admin/runners/).


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Register runner"
  community.general.gitlab_runner:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    registration_token: 4gfdsg345
    description: Docker Machine t1
    state: present
    active: true
    tag_list: ['docker']
    run_untagged: false
    locked: false
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Delete runner"
  community.general.gitlab_runner:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    description: Docker Machine t1
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete an owned runner as a non-admin
  community.general.gitlab_runner:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    description: Docker Machine t1
    owned: true
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Register runner for a specific project
  community.general.gitlab_runner:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    registration_token: 4gfdsg345
    description: MyProject runner
    state: present
    project: mygroup/mysubgroup/myproject

Inputs

    
group:
    description:
    - ID or full path of the group in the form group/subgroup.
    - Mutually exclusive with O(owned) and O(project).
    - Must be group's numeric ID if O(registration_token) is not set and O(state=present).
    type: str
    version_added: 6.5.0
    version_added_collection: community.general

owned:
    default: false
    description:
    - Searches only runners available to the user when searching for existing, when false
      admin token required.
    - Mutually exclusive with O(project) since community.general 4.5.0.
    - Mutually exclusive with O(group).
    type: bool
    version_added: 2.0.0
    version_added_collection: community.general

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Make sure that the runner with the same name exists with the same configuration
      or delete the runner with the same name.
    required: false
    type: str

active:
    default: true
    description:
    - Define if the runners is immediately active after creation.
    - Mutually exclusive with O(paused).
    required: false
    type: bool

locked:
    default: false
    description:
    - Determines if the runner is locked or not.
    required: false
    type: bool

paused:
    default: false
    description:
    - Define if the runners is active or paused after creation.
    - Mutually exclusive with O(active).
    required: false
    type: bool
    version_added: 8.1.0
    version_added_collection: community.general

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

ca_path:
    description:
    - The CA certificates bundle to use to verify GitLab server certificate.
    type: str
    version_added: 8.1.0
    version_added_collection: community.general

project:
    description:
    - ID or full path of the project in the form of group/name.
    - Mutually exclusive with O(owned) since community.general 4.5.0.
    - Mutually exclusive with O(group).
    - Must be project's numeric ID if O(registration_token) is not set and O(state=present).
    type: str
    version_added: 3.7.0
    version_added_collection: community.general

tag_list:
    default: []
    description: The tags that apply to the runner.
    elements: str
    required: false
    type: list

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

description:
    aliases:
    - name
    description:
    - The unique name of the runner.
    required: true
    type: str

access_level:
    choices:
    - not_protected
    - ref_protected
    description:
    - Determines if a runner can pick up jobs only from protected branches.
    - If O(access_level_on_creation) is not explicitly set to V(true), this option is
      ignored on registration and is only applied on updates.
    - If set to V(not_protected), runner can pick up jobs from both protected and unprotected
      branches.
    - If set to V(ref_protected), runner can pick up jobs only from protected branches.
    - Before community.general 8.0.0 the default was V(ref_protected). This was changed
      to no default in community.general 8.0.0. If this option is not specified explicitly,
      GitLab will use V(not_protected) on creation, and the value set will not be changed
      on any updates.
    required: false
    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

run_untagged:
    default: true
    description:
    - Run untagged jobs or not.
    required: false
    type: bool

api_job_token:
    description:
    - GitLab CI job token for logging in.
    type: str
    version_added: 4.2.0
    version_added_collection: community.general

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

api_oauth_token:
    description:
    - GitLab OAuth token for logging in.
    type: str
    version_added: 4.2.0
    version_added_collection: community.general

maximum_timeout:
    default: 3600
    description:
    - The maximum time that a runner has to complete a specific job.
    required: false
    type: int

registration_token:
    description:
    - The registration token is used to register new runners before GitLab 16.0.
    - Required if O(state=present) for GitLab < 16.0.
    - If set, the runner will be created using the old runner creation workflow.
    - If not set, the runner will be created using the new runner creation workflow, introduced
      in GitLab 16.0.
    - If not set, requires python-gitlab >= 4.0.0.
    type: str

access_level_on_creation:
    default: true
    description:
    - Whether the runner should be registered with an access level or not.
    - If set to V(true), the value of O(access_level) is used for runner registration.
    - If set to V(false), GitLab registers the runner with the default access level.
    - The default of this option changed to V(true) in community.general 7.0.0. Before,
      it was V(false).
    required: false
    type: bool
    version_added: 6.3.0
    version_added_collection: community.general

Outputs

error:
  description: the error message returned by the GitLab API
  returned: failed
  sample: '400: path is already in use'
  type: str
msg:
  description: Success or failure message
  returned: always
  sample: Success
  type: str
result:
  description: json parsed response from the server
  returned: always
  type: dict
runner:
  description: API object
  returned: always
  type: dict