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 中的新功能

概要

  • 当标签不存在时,将创建它。

  • 当标签存在时,如果值不同,则其值将被更新。

  • 标签可以被清除。

要求

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

参数

参数

注释

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 证书包。

group

字符串

组的路径。需要此参数或 project 之一。

labels

列表 / 元素=字典

表示 gitlab 项目或组标签的字典列表。

默认值: []

color

字符串

标签的颜色。

state=present 时为必需。

description

字符串

标签的描述。

name

字符串 / 必需

标签的名称。

new_name

字符串

用于更改标签名称的可选字段。

priority

整数

用于赋予标签优先级的整数值。

project

字符串

项目的路径和名称。需要此参数或 group 之一。

purge

布尔值

当设置为 true 时,删除任务中未提及的所有标签。

选择

  • false ← (默认)

  • true

state

字符串

创建或删除项目或组标签。

选择

  • "present" ← (默认)

  • "absent"

validate_certs

布尔值

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

选择

  • false

  • true ← (默认)

属性

属性

支持

描述

check_mode

支持: 完全

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

diff_mode

支持:

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

示例

# 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

返回值

常见的返回值记录在此处,以下是此模块独有的字段

描述

labels

字典

四个标签列表,分别对应已添加、已更新、已删除或存在的标签。

返回: 成功

added

list / elements=string

已创建的标签列表。

返回: 总是

示例: ["abcd", "label-one"]

removed

list / elements=string

已删除的标签列表。

返回: 总是

示例: ["defg", "new-label"]

untouched

list / elements=string

已存在的标签列表。

返回: 总是

示例: ["defg", "new-label"]

updated

list / elements=string

值已被设置的预先存在的标签列表。

返回: 总是

示例: ["defg", "new-label"]

labels_obj

字典

API 对象。

返回: 成功

作者

  • Gabriele Pongelli (@gpongelli)