community.general.gitlab_group_members 模块 – 管理 GitLab 服务器上的组成员

注意

此模块是 community.general 集合(版本 10.1.0)的一部分。

如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general。您需要其他要求才能使用此模块,请参阅 要求了解详细信息。

要在 playbook 中使用它,请指定:community.general.gitlab_group_members

community.general 1.2.0 中的新增功能

概要

  • 此模块允许在 GitLab 上向组添加和删除成员,或更改组成员的访问级别。

要求

以下要求需要在执行此模块的主机上满足。

参数

参数

注释

access_level

字符串

用户的访问级别。

如果 state=present,则用户状态设置为 present 时,此项为必需。

gitlab_users_access 互斥。

选项

  • "guest"

  • "reporter"

  • "developer"

  • "maintainer"

  • "owner"

api_job_token

字符串

在 community.general 4.2.0 中添加

用于登录的 GitLab CI 作业令牌。

api_oauth_token

字符串

在 community.general 4.2.0 中添加

用于登录的 GitLab OAuth 令牌。

api_password

字符串

用于 API 身份验证的密码。

api_token

字符串

具有 API 权限的 GitLab 访问令牌。

api_url

字符串

API 的可解析端点。

api_username

字符串

用于 API 身份验证的用户名。

ca_path

字符串

在 community.general 8.1.0 中添加

用于验证 GitLab 服务器证书的 CA 证书捆绑包。

gitlab_group

字符串 / 必需

要添加/删除成员的 GitLab 组的 full_path

自 community.general 6.0.0 起,不允许将其设置为 namepath。请改用 full_path

gitlab_user

列表 / 元素=字符串

要添加到/从 GitLab 组中删除的用户名或用户名列表。

gitlab_users_access 互斥。

gitlab_users_access

列表 / 元素=字典

在 community.general 3.6.0 中添加

提供用户到访问级别映射的列表。

此列表中的每个字典都指定一个用户(通过用户名)以及该用户应具有的访问级别。

gitlab_useraccess_level 互斥。

purge_users 一起使用,以从组中删除所有未在此处指定的用户。

access_level

字符串 / 必需

用户的访问级别。

如果 state=present,则用户状态设置为 present 时,此项为必需。

选项

  • "guest"

  • "reporter"

  • "developer"

  • "maintainer"

  • "owner"

name

字符串 / 必需

要添加到/从 GitLab 组中删除的用户名或用户名列表。

purge_users

列表 / 元素=字符串

在 community.general 3.6.0 中添加

根据给定的 gitlab_user/ gitlab_users_access 列表,添加/移除具有指定 access_level 的用户。如果省略,则不会清除孤立的成员。

仅在 state=present 时使用。

选项

  • "guest"

  • "reporter"

  • "developer"

  • "maintainer"

  • "owner"

state

字符串

组成员在组中的状态。

当为 present 时,它会将用户添加到 GitLab 组。

当为 absent 时,它会从 GitLab 组中移除用户。

选项

  • "present" ← (默认)

  • "absent"

validate_certs

布尔值

当提供 HTTPS 端点时,是否验证 SSL 证书。

选项

  • false

  • true ← (默认)

属性

属性

支持

描述

check_mode

支持: 完全

可以在 check_mode 模式下运行,并返回更改状态的预测,而无需修改目标。

diff_mode

支持:

在 diff 模式下,将会返回已更改(或可能需要在 check_mode 中更改)的详细信息。

示例

- name: Add a user to a GitLab Group
  community.general.gitlab_group_members:
    api_url: 'https://gitlab.example.com'
    api_token: 'Your-Private-Token'
    gitlab_group: groupname
    gitlab_user: username
    access_level: developer
    state: present

- name: Remove a user from a GitLab Group
  community.general.gitlab_group_members:
    api_url: 'https://gitlab.example.com'
    api_token: 'Your-Private-Token'
    gitlab_group: groupname
    gitlab_user: username
    state: absent

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

- name: Add a list of Users with Dedicated Access Levels to A GitLab Group
  community.general.gitlab_group_members:
    api_url: 'https://gitlab.example.com'
    api_token: 'Your-Private-Token'
    gitlab_group: groupname
    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_group_members:
    api_url: 'https://gitlab.example.com'
    api_token: 'Your-Private-Token'
    gitlab_group: groupname
    gitlab_user: username
    access_level: developer
    pruge_users: developer
    state: present

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

作者

  • Zainab Alsaffar (@zanssa)