ansible.builtin.gitlab_deploy_key (v2.6.20) — module

Manages GitLab project deploy keys.

| "added in version" 2.6 of ansible.builtin"

Authors: Marcus Watkins (@marwatk)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.6.20

Description

Adds, updates and removes project deploy keys

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Example adding a project deploy key
- gitlab_deploy_key:
    api_url: https://gitlab.example.com/api
    access_token: "{{ access_token }}"
    project: "my_group/my_project"
    title: "Jenkins CI"
    state: present
    key: "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9w..."
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Update the above deploy key to add push access
- gitlab_deploy_key:
    api_url: https://gitlab.example.com/api
    access_token: "{{ access_token }}"
    project: "my_group/my_project"
    title: "Jenkins CI"
    state: present
    key: "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9w..."
    can_push: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Remove the previous deploy key from the project
- gitlab_deploy_key:
    api_url: https://gitlab.example.com/api
    access_token: "{{ access_token }}"
    project: "my_group/my_project"
    state: absent
    key: "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9w..."

Inputs

    
key:
    description:
    - Deploy key
    required: true

state:
    choices:
    - present
    - absent
    default: present
    description:
    - When C(present) the deploy key added to the project if it doesn't exist.
    - When C(absent) it will be removed from the project if it exists
    required: true

title:
    description:
    - Deploy key's title
    required: true

api_url:
    description:
    - GitLab API url, e.g. https://gitlab.example.com/api
    required: true

project:
    description:
    - Numeric project id or name of project in the form of group/name
    required: true

can_push:
    default: 'no'
    description:
    - Whether this key can push to the project
    type: bool

access_token:
    description:
    - The oauth key provided by GitLab. One of access_token or private_token is required.
      See https://docs.gitlab.com/ee/api/oauth2.html
    required: false

private_token:
    description:
    - Personal access token to use. One of private_token or access_token is required.
      See https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html
    required: false

Outputs

error:
  description: the error message returned by the Gitlab API
  returned: failed
  sample: '400: key is already in use'
  type: string
msg:
  description: Success or failure message
  returned: always
  sample: Success
  type: string
previous_version:
  description: object describing the state prior to this task
  returned: changed
  type: dict
result:
  description: json parsed response from the server
  returned: always
  type: dict