community.general.gitlab_user (8.5.0) — module

Creates/updates/deletes/blocks/unblocks GitLab Users

Authors: Werner Dijkerman (@dj-wasabi), Guillaume Martinez (@Lunik), Lennert Mertens (@LennertMertens), Stef Graces (@stgrace)

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

When the user does not exist in GitLab, it will be created.

When the user exists and state=absent, the user will be deleted.

When the user exists and state=blocked, the user will be blocked.

When changes are made to user, the user will be updated.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Delete GitLab User"
  community.general.gitlab_user:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    username: myusername
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Create GitLab User"
  community.general.gitlab_user:
    api_url: https://gitlab.example.com/
    validate_certs: true
    api_username: dj-wasabi
    api_password: "MySecretPassword"
    name: My Name
    username: myusername
    password: mysecretpassword
    email: me@example.com
    sshkey_name: MySSH
    sshkey_file: ssh-rsa AAAAB3NzaC1yc...
    state: present
    group: super_group/mon_group
    access_level: owner
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Create GitLab User using external identity provider"
  community.general.gitlab_user:
    api_url: https://gitlab.example.com/
    validate_certs: true
    api_token: "{{ access_token }}"
    name: My Name
    username: myusername
    password: mysecretpassword
    email: me@example.com
    identities:
    - provider: Keycloak
      extern_uid: f278f95c-12c7-4d51-996f-758cc2eb11bc
    state: present
    group: super_group/mon_group
    access_level: owner
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Block GitLab User"
  community.general.gitlab_user:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    username: myusername
    state: blocked
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: "Unblock GitLab User"
  community.general.gitlab_user:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    username: myusername
    state: unblocked

Inputs

    
name:
    description:
    - Name of the user you want to create.
    - Required only if O(state=present).
    type: str

email:
    description:
    - The email that belongs to the user.
    - Required only if O(state=present).
    type: str

group:
    description:
    - Id or Full path of parent group in the form of group/name.
    - Add user as a member to this group.
    type: str

state:
    choices:
    - present
    - absent
    - blocked
    - unblocked
    default: present
    description:
    - Create, delete or block a user.
    type: str

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

confirm:
    default: true
    description:
    - Require confirmation.
    type: bool

isadmin:
    default: false
    description:
    - Grant admin privileges to the user.
    type: bool

external:
    default: false
    description:
    - Define external parameter for this user.
    type: bool

password:
    description:
    - The password of the user.
    - GitLab server enforces minimum password length to 8, set this value with 8 or more
      characters.
    type: str

username:
    description:
    - The username of the user.
    required: true
    type: str

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

identities:
    description:
    - List of identities to be added/updated for this user.
    - To remove all other identities from this user, set O(overwrite_identities=true).
    elements: dict
    suboptions:
      extern_uid:
        description:
        - User ID for external identity.
        type: str
      provider:
        description:
        - The name of the external identity provider
        type: str
    type: list
    version_added: 3.3.0
    version_added_collection: community.general

sshkey_file:
    description:
    - The SSH public key itself.
    type: str

sshkey_name:
    description:
    - The name of the SSH public key.
    type: str

access_level:
    choices:
    - guest
    - reporter
    - developer
    - master
    - maintainer
    - owner
    default: guest
    description:
    - The access level to the group. One of the following can be used.
    - guest
    - reporter
    - developer
    - master (alias for maintainer)
    - maintainer
    - owner
    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

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

reset_password:
    default: false
    description:
    - Whether the user can change its password or not.
    type: bool
    version_added: 3.3.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

sshkey_expires_at:
    description:
    - The expiration date of the SSH public key in ISO 8601 format C(YYYY-MM-DDTHH:MM:SSZ).
    - This is only used when adding new SSH public keys.
    type: str
    version_added: 3.1.0
    version_added_collection: community.general

overwrite_identities:
    default: false
    description:
    - Overwrite identities with identities added in this module.
    - This means that all identities that the user has and that are not listed in O(identities)
      are removed from the user.
    - This is only done if a list is provided for O(identities). To remove all identities,
      provide an empty list.
    type: bool
    version_added: 3.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
user:
  description: API object
  returned: always
  type: dict