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

Manages GitLab project deploy keys.

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

Authors: Marcus Watkins (@marwatk), Guillaume Martinez (@Lunik)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.9.27

Description

Adds, updates and removes project deploy keys


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Adding a project deploy key"
  gitlab_deploy_key:
    api_url: https://gitlab.example.com/
    api_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.
- name: "Update the above deploy key to add push access"
  gitlab_deploy_key:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    project: "my_group/my_project"
    title: "Jenkins CI"
    state: present
    can_push: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Remove the previous deploy key from the project"
  gitlab_deploy_key:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    project: "my_group/my_project"
    state: absent
    key: "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9w..."

Inputs

    
key:
    description:
    - Deploy key
    required: true
    type: str

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
    type: str

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

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

project:
    description:
    - Id or Full path of project in the form of group/name
    required: true
    type: str

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

api_token:
    aliases:
    - private_token
    - access_token
    description:
    - GitLab token for logging in.
    type: str
    version_added: '2.8'
    version_added_collection: ansible.builtin

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

deploy_key:
  description: API object
  returned: always
  type: dict
error:
  description: the error message returned by the GitLab API
  returned: failed
  sample: '400: key 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