community.general.gitlab_project_variable 模块 – 创建/更新/删除 GitLab 项目变量
注意
此模块是 community.general 集合 (版本 10.1.0) 的一部分。
如果您正在使用 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.general。您需要其他要求才能使用此模块,请参阅 需求 获取详细信息。
要在剧本中使用它,请指定:community.general.gitlab_project_variable。
概要
- 如果项目变量不存在,则会创建它。 
- 如果项目变量存在,则当值不同时会更新其值。 
- 剧本中未更改的变量,但在 GitLab 项目中已更改,则保持不变 ( - purge=false) 或将被删除 (- purge=true)。
需求
以下需求是在执行此模块的主机上需要的。
- python-gitlab Python 模块 
- requests (Python 库 https://pypi.ac.cn/project/requests/) 
参数
| 参数 | 注释 | 
|---|---|
| 用于登录的 GitLab CI 作业令牌。 | |
| 用于登录的 GitLab OAuth 令牌。 | |
| 用于针对 API 进行身份验证的密码。 | |
| 具有 API 权限的 GitLab 访问令牌。 | |
| API 的可解析端点。 | |
| 用于针对 API 进行身份验证的用户名。 | |
| 用于验证 GitLab 服务器证书的 CA 证书包。 | |
| 项目的路径和名称。 | |
| 设置为 true 时,任务中未更改的所有变量都将被删除。 选项 
 | |
| 创建或删除项目变量。 可能的值为 present 和 absent。 选项 
 | |
| 是否在提供 HTTPS 端点时验证 SSL 证书。 选项 
 | |
| 变量值是否被屏蔽。 对屏蔽值的支持需要 GitLab >= 11.10。 选项 
 | |
| 变量的名称。 | |
| 变量值是否受保护。 对受保护值的支持需要 GitLab >= 9.3。 选项 
 | |
| 变量值是否为原始值。 对原始值的支持需要 GitLab >= 15.7。 选项 
 | |
| 变量值。 当  | |
| 变量是环境变量( 对  选项 
 | |
| 当列表元素是一个简单的键值对时,masked、raw 和 protected 将被设置为 false。 当列表元素是一个包含键  对受保护值的支持需要 GitLab >= 9.3。 对屏蔽值的支持需要 GitLab >= 11.10。 对原始值的支持需要 GitLab >= 15.7。 对 environment_scope 的支持需要 GitLab Premium >= 13.11。 对 variable_type 的支持需要 GitLab >= 11.11。 
 字段  字段  如果屏蔽值,则该值必须为 Base64 编码,且长度至少为 8 个字符。有关屏蔽变量的可接受值的详细信息,请参阅 GitLab 文档 (https://docs.gitlab.com/ce/ci/variables/#masked-variables)。 默认值:  | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持:完全支持 | 可以在  | |
| 支持:不支持 | 处于 diff 模式时,将返回有关已更改内容(或可能需要在  | 
示例
- name: Set or update some CI/CD variables
  community.general.gitlab_project_variable:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: markuman/dotfiles
    purge: false
    variables:
      - name: ACCESS_KEY_ID
        value: abc123
      - name: SECRET_ACCESS_KEY
        value: dassgrfaeui8989
        masked: true
        protected: true
        environment_scope: production
- name: Set or update some CI/CD variables
  community.general.gitlab_project_variable:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: markuman/dotfiles
    purge: false
    vars:
      ACCESS_KEY_ID: abc123
      SECRET_ACCESS_KEY:
        value: 3214cbad
        masked: true
        protected: true
        variable_type: env_var
        environment_scope: '*'
- name: Set or update some CI/CD variables with raw value
  community.general.gitlab_project_variable:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: markuman/dotfiles
    purge: false
    vars:
      ACCESS_KEY_ID: abc123
      SECRET_ACCESS_KEY:
        value: 3214cbad
        masked: true
        protected: true
        raw: true
        variable_type: env_var
        environment_scope: '*'
- name: Set or update some CI/CD variables with expandable value
  community.general.gitlab_project_variable:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: markuman/dotfiles
    purge: false
    vars:
      ACCESS_KEY_ID: abc123
      SECRET_ACCESS_KEY:
        value: '$MY_OTHER_VARIABLE'
        masked: true
        protected: true
        raw: false
        variable_type: env_var
        environment_scope: '*'
- name: Delete one variable
  community.general.gitlab_project_variable:
    api_url: https://gitlab.com
    api_token: secret_access_token
    project: markuman/dotfiles
    state: absent
    vars:
      ACCESS_KEY_ID: abc123
返回值
常见的返回值已在 此处 记录,以下是此模块独有的字段
| 键 | 描述 | 
|---|---|
| 四个变量名列表,分别表示已添加、已更新、已删除或存在的变量。 返回:始终返回 | |
| 已创建的变量列表。 返回:始终返回 示例:  | |
| 已删除的变量列表。 返回:始终返回 示例:  | |
| 存在的变量列表。 返回:始终返回 示例:  | |
| 值已更改的变量列表。 返回:始终返回 示例:  | 
