community.general.gitlab_label 模块 – 创建/更新/删除属于项目或组的 GitLab 标签。
注意
此模块是 community.general 集合(版本 10.1.0)的一部分。
如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用: ansible-galaxy collection install community.general。您需要进一步的要求才能使用此模块,请参阅 要求 了解详细信息。
要在 playbook 中使用它,请指定: community.general.gitlab_label。
community.general 8.3.0 中的新增功能
概要
- 当标签不存在时,将创建标签。 
- 当标签存在时,如果值不同,则其值将被更新。 
- 标签可以被清除。 
要求
以下要求需要在执行此模块的主机上满足。
- python-gitlab python 模块 
- requests (Python 库 https://pypi.ac.cn/project/requests/) 
参数
| 参数 | 注释 | 
|---|---|
| 用于登录的 GitLab CI 作业令牌。 | |
| 用于登录的 GitLab OAuth 令牌。 | |
| 用于针对 API 进行身份验证的密码。 | |
| 具有 API 权限的 GitLab 访问令牌。 | |
| API 的可解析端点。 | |
| 用于针对 API 进行身份验证的用户名。 | |
| 用于验证 GitLab 服务器证书的 CA 证书捆绑包。 | |
| 组的路径。需要此参数或  | |
| 表示 gitlab 项目或组标签的字典列表。 默认值:  | |
| 标签的颜色。 当  | |
| 标签的描述。 | |
| 标签的名称。 | |
| 更改标签名称的可选字段。 | |
| 为标签设置优先级的整数值。 | |
| 项目的路径和名称。需要此参数或  | |
| 设置为  选项 
 | |
| 创建或删除项目或组标签。 选项 
 | |
| 在提供 HTTPS 端点时是否验证 SSL 证书。 选项 
 | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持:完全 | 可以在  | |
| 支持:无 | 当处于差异模式时,将返回已更改的内容的详细信息(或在  | 
示例
# same project's task can be executed for group
- name: Create one Label
  community.general.gitlab_label:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: "group1/project1"
    labels:
      - name: label_one
        color: "#123456"
    state: present
- name: Create many group labels
  community.general.gitlab_label:
    api_url: https://gitlab.com
    api_token: secret_access_token
    group: "group1"
    labels:
      - name: label_one
        color: "#123456"
        description: this is a label
        priority: 20
      - name: label_two
        color: "#554422"
    state: present
- name: Create many project labels
  community.general.gitlab_label:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: "group1/project1"
    labels:
      - name: label_one
        color: "#123456"
        description: this is a label
        priority: 20
      - name: label_two
        color: "#554422"
    state: present
- name: Set or update some labels
  community.general.gitlab_label:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: "group1/project1"
    labels:
      - name: label_one
        color: "#224488"
    state: present
- name: Add label in check mode
  community.general.gitlab_label:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: "group1/project1"
    labels:
      - name: label_one
        color: "#224488"
    check_mode: true
- name: Delete Label
  community.general.gitlab_label:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: "group1/project1"
    labels:
      - name: label_one
    state: absent
- name: Change Label name
  community.general.gitlab_label:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: "group1/project1"
    labels:
      - name: label_one
        new_name: label_two
    state: absent
- name: Purge all labels
  community.general.gitlab_label:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: "group1/project1"
    purge: true
- name: Delete many labels
  community.general.gitlab_label:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: "group1/project1"
    state: absent
    labels:
      - name: label-abc123
      - name: label-two
返回值
常见的返回值记录在此处,以下是此模块独有的字段
| 键 | 描述 | 
|---|---|
| 包含已添加、已更新、已删除或存在的标签的四个列表。 返回: 成功 | |
| 已创建的标签的列表。 返回: 总是 示例:  | |
| 已删除的标签的列表。 返回: 总是 示例:  | |
| 存在的标签的列表。 返回: 总是 示例:  | |
| 值已设置的先前存在的标签的列表。 返回: 总是 示例:  | |
| API 对象。 返回: 成功 | 
