community.general.gitlab_project_members 模块 – 在 GitLab 服务器上管理项目成员
注意
此模块是 community.general 集合 (版本 10.1.0) 的一部分。
如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.general。您需要其他要求才能使用此模块,有关详细信息,请参阅 要求。
要在剧本中使用它,请指定:community.general.gitlab_project_members。
community.general 2.2.0 中的新增功能
概要
- 此模块允许向 GitLab 项目添加和删除成员,或更改项目中成员的访问级别。 
要求
在执行此模块的主机上需要以下要求。
- 对 GitLab 服务器上的项目的拥有者或维护者权限 
- python-gitlab python 模块 <= 1.15.0 
- requests (Python 库 https://pypi.ac.cn/project/requests/) 
参数
| 参数 | 注释 | 
|---|---|
| 用于登录的 GitLab CI 作业令牌。 | |
| 用于登录的 GitLab OAuth 令牌。 | |
| 用于针对 API 进行身份验证的密码。 | |
| 具有 API 权限的 GitLab 访问令牌。 | |
| API 的可解析端点。 | |
| 用于针对 API 进行身份验证的用户名。 | |
| 用于验证 GitLab 服务器证书的 CA 证书包。 | |
| 要添加到/从 GitLab 项目中删除的用户名或用户名列表。 与  | |
| 提供用户到访问级别映射的列表。 此列表中的每个字典都指定一个用户(按用户名)以及用户应具有的访问级别。 与  与  | |
| 要添加到/从 GitLab 项目中删除的用户名或用户名列表。 | |
| 添加/删除成员的 GitLab 项目的名称(或完整路径)。 | |
| 添加/删除给定 access_level 的用户以匹配给定的  仅在  选项 
 | |
| 项目中成员的状态。 在  在  选项 
 | |
| 是否在提供 HTTPS 端点时验证 SSL 证书。 选项 
 | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持:完全支持 | 可以在  | |
| 支持:不支持 | 在差异模式下,将返回关于已更改内容(或可能需要在 | 
示例
- 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'
    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
    purge_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
