community.general.gitlab_project_members – Manage project members on GitLab Server

Note

This plugin is part of the community.general collection (version 3.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_project_members.

New in version 2.2.0: of community.general

Synopsis

  • This module allows to add and remove members to/from a project, or change a member’s access level in a project on GitLab.

Requirements

The below requirements are needed on the host that executes this module.

  • python-gitlab python module <= 1.15.0

  • owner or maintainer rights to project on the GitLab server

Parameters

Parameter

Comments

access_level

string

The access level for the user.

Required if state=present, user state is set to present.

Choices:

  • guest

  • reporter

  • developer

  • maintainer

api_password

string

The password to use for authentication against the API.

api_token

string / required

A personal access token to authenticate with the GitLab API.

api_url

string

The resolvable endpoint for the API.

api_username

string

The username to use for authentication against the API.

gitlab_user

list / elements=string

A username or a list of usernames to add to/remove from the GitLab project.

Mutually exclusive with gitlab_users_access.

gitlab_users_access

list / elements=dictionary

added in 3.7.0 of community.general

Provide a list of user to access level mappings.

Every dictionary in this list specifies a user (by username) and the access level the user should have.

Mutually exclusive with gitlab_user and access_level.

Use together with purge_users to remove all users not specified here from the project.

access_level

string / required

The access level for the user.

Required if state=present, user state is set to present.

Choices:

  • guest

  • reporter

  • developer

  • maintainer

name

string / required

A username or a list of usernames to add to/remove from the GitLab project.

project

string / required

The name (or full path) of the GitLab project the member is added to/removed from.

purge_users

list / elements=string

added in 3.7.0 of community.general

Adds/remove users of the given access_level to match the given gitlab_user/gitlab_users_access list. If omitted do not purge orphaned members.

Is only used when state=present.

Choices:

  • guest

  • reporter

  • developer

  • maintainer

state

string

State of the member in the project.

On present, it adds a user to a GitLab project.

On absent, it removes a user from a GitLab project.

Choices:

  • present ← (default)

  • absent

validate_certs

boolean

Whether or not to validate TLS/SSL certificates when supplying a HTTPS endpoint.

Should only be set to false if you can guarantee that you are talking to the correct server and no man-in-the-middle attack can happen.

Choices:

  • no

  • yes ← (default)

Notes

Note

  • Supports check_mode.

Examples

- name: Add a user to a GitLab Project
  community.general.gitlab_project_members:
    api_url: 'https://gitlab.example.com'
    api_token: 'Your-Private-Token'
    validate_certs: True
    project: projectname
    gitlab_user: username
    access_level: developer
    state: present

- name: Remove a user from a GitLab project
  community.general.gitlab_project_members:
    api_url: 'https://gitlab.example.com'
    api_token: 'Your-Private-Token'
    validate_certs: False
    project: projectname
    gitlab_user: username
    state: absent

- name: Add a list of Users to A GitLab project
  community.general.gitlab_project_members:
    api_url: 'https://gitlab.example.com'
    api_token: 'Your-Private-Token'
    gitlab_project: projectname
    gitlab_user:
      - user1
      - user2
    access_level: developer
    state: present

- name: Add a list of Users with Dedicated Access Levels to A GitLab project
  community.general.gitlab_project_members:
    api_url: 'https://gitlab.example.com'
    api_token: 'Your-Private-Token'
    project: projectname
    gitlab_users_access:
      - name: user1
        access_level: developer
      - name: user2
        access_level: maintainer
    state: present

- name: Add a user, remove all others which might be on this access level
  community.general.gitlab_project_members:
    api_url: 'https://gitlab.example.com'
    api_token: 'Your-Private-Token'
    project: projectname
    gitlab_user: username
    access_level: developer
    pruge_users: developer
    state: present

- name: Remove a list of Users with Dedicated Access Levels to A GitLab project
  community.general.gitlab_project_members:
    api_url: 'https://gitlab.example.com'
    api_token: 'Your-Private-Token'
    project: projectname
    gitlab_users_access:
      - name: user1
        access_level: developer
      - name: user2
        access_level: maintainer
    state: absent

Authors

  • Sergey Mikhaltsov (@metanovii)

  • Zainab Alsaffar (@zanssa)