community.general.gitlab_deploy_key module – Manages GitLab project deploy keys.
Note
This module is part of the community.general collection (version 4.8.3).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.general
.
To use it in a playbook, specify: community.general.gitlab_deploy_key
.
Requirements
The below requirements are needed on the host that executes this module.
python >= 2.7
python-gitlab python module
requests (Python library https://pypi.org/project/requests/)
Parameters
Parameter |
Comments |
---|---|
GitLab CI job token for logging in. |
|
GitLab OAuth token for logging in. |
|
The password to use for authentication against the API |
|
GitLab access token with API permissions. |
|
The resolvable endpoint for the API |
|
The username to use for authentication against the API |
|
Whether this key can push to the project. Choices:
|
|
Deploy key |
|
Id or Full path of project in the form of group/name. |
|
When When Choices:
|
|
Deploy key’s title. |
|
Whether or not to validate SSL certs when supplying a https endpoint. Choices:
|
Examples
- name: "Adding a project deploy key"
community.general.gitlab_deploy_key:
api_url: https://gitlab.example.com/
api_token: "{{ api_token }}"
project: "my_group/my_project"
title: "Jenkins CI"
state: present
key: "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9w..."
- name: "Update the above deploy key to add push access"
community.general.gitlab_deploy_key:
api_url: https://gitlab.example.com/
api_token: "{{ api_token }}"
project: "my_group/my_project"
title: "Jenkins CI"
state: present
can_push: yes
- name: "Remove the previous deploy key from the project"
community.general.gitlab_deploy_key:
api_url: https://gitlab.example.com/
api_token: "{{ api_token }}"
project: "my_group/my_project"
state: absent
key: "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9w..."
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
API object Returned: always |
|
the error message returned by the GitLab API Returned: failed Sample: “400: key is already in use” |
|
Success or failure message Returned: always Sample: “Success” |
|
json parsed response from the server Returned: always |
Authors
Marcus Watkins (@marwatk)
Guillaume Martinez (@Lunik)
Collection links
Issue Tracker Repository (Sources) Submit a bug report Request a feature Communication