community.general.gitlab_project 模块 – 创建/更新/删除 GitLab 项目
注意
此模块是 community.general 集合(版本 10.1.0)的一部分。
如果您正在使用 ansible
包,您可能已经安装了这个集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.general
。您需要进一步的要求才能使用此模块,请参阅 要求 以了解详细信息。
要在 Playbook 中使用它,请指定:community.general.gitlab_project
。
概要
当项目在 GitLab 中不存在时,将创建该项目。
当项目存在且
state=absent
时,将删除该项目。当对项目进行更改时,将更新该项目。
要求
以下要求需要在执行此模块的主机上满足。
python-gitlab python 模块
requests(Python 库 https://pypi.ac.cn/project/requests/)
参数
参数 |
注释 |
---|---|
允许在存在跳过管道时合并。 选项
|
|
用于登录的 GitLab CI 作业令牌。 |
|
用于登录的 GitLab OAuth 令牌。 |
|
用于对 API 进行身份验证的密码。 |
|
具有 API 权限的 GitLab 访问令牌。 |
|
API 的可解析端点。 |
|
用于对 API 进行身份验证的用户名。 |
|
用于配置头像的绝对路径图像。文件大小不应超过 200 kb。 此选项仅在创建时使用,不用于更新。 |
|
选项
|
|
用于验证 GitLab 服务器证书的 CA 证书包。 |
|
此项目的 CI 配置文件自定义路径。 |
|
项目容器注册表的清理策略。 |
|
应多久运行一次清理。 选项
|
|
启用清理策略。 选项
|
|
每个图像名称保留的标签数。
选项
|
|
销毁与此正则表达式匹配的标签。 |
|
保留与此正则表达式匹配的标签。 |
|
销毁比此更早的标签。
选项
|
|
选项
|
|
此项目的默认分支名称。 对于项目创建,此选项需要 对于项目更新,该分支必须存在。 自 community.general 8.0.0 起支持项目的默认分支更新。 |
|
项目的描述。 |
|
选项
|
|
选项
|
|
选项
|
|
此项目所属组的 ID 或完整路径。 |
|
将导入到 GitLab 中的 Git 仓库。 GitLab 服务器需要对此 Git 仓库具有读取权限。 |
|
选项
|
|
将使用默认的 仅在创建项目时使用,否则将被忽略。 选项
|
|
选项
|
|
启用 Git 大文件系统来管理大型文件,如音频、视频和图形文件。 选项
|
|
对合并的要求是什么。 可能的值为 选项
|
|
是否可以创建合并请求。 选项
|
|
选项
|
|
选项
|
|
项目的名称。 |
|
必须解决合并请求 (MR) 上的所有讨论。 选项
|
|
仅当管道成功时才允许合并。 选项
|
|
启用 GitLab 包仓库。 选项
|
|
选项
|
|
要创建的项目的路径,这将是 server_url/<group>/path。 如果未提供,将使用名称。 |
|
选项
|
|
合并后删除源分支。 选项
|
|
选项
|
|
选项
|
|
启用服务台。 选项
|
|
为此项目启用共享 runners。 选项
|
|
是否应提供创建代码片段的功能。 选项
|
|
合并时压缩提交。 选项
|
|
创建或删除项目。 可能的值为 present 和 absent。 选项
|
|
要分配给项目的主题或主题列表。 它与旧的 GitLab 服务器版本(14 之前的版本,对应于 |
|
用于在用户的名称下创建个人项目。 |
|
当提供 HTTPS 端点时,是否验证 SSL 证书。 选项
|
|
选项
|
|
是否应该为该项目提供 Wiki。 选项
|
属性
属性 |
支持 |
描述 |
---|---|---|
支持: 完全 |
可以在 |
|
支持: 无 |
在 diff 模式下,将返回已更改(或可能需要在 |
示例
- name: Create GitLab Project
community.general.gitlab_project:
api_url: https://gitlab.example.com/
api_token: "{{ api_token }}"
name: my_first_project
group: "10481470"
- name: Delete GitLab Project
community.general.gitlab_project:
api_url: https://gitlab.example.com/
api_token: "{{ access_token }}"
name: my_first_project
state: absent
delegate_to: localhost
- name: Create GitLab Project in group Ansible
community.general.gitlab_project:
api_url: https://gitlab.example.com/
validate_certs: true
api_username: dj-wasabi
api_password: "MySecretPassword"
name: my_first_project
group: ansible
issues_enabled: false
merge_method: rebase_merge
wiki_enabled: true
snippets_enabled: true
import_url: http://git.example.com/example/lab.git
initialize_with_readme: true
state: present
delegate_to: localhost
- name: get the initial root password
ansible.builtin.shell: |
grep 'Password:' /etc/gitlab/initial_root_password | sed -e 's/Password\: \(.*\)/\1/'
register: initial_root_password
- name: Create a GitLab Project using a username/password via oauth_token
community.general.gitlab_project:
api_url: https://gitlab.example.com/
api_username: root
api_password: "{{ initial_root_password }}"
name: my_second_project
group: "10481470"
返回值
常见的返回值在此处记录 此处,以下是此模块特有的字段
键 |
描述 |
---|---|
GitLab API 返回的错误消息。 已返回: 失败 示例: |
|
成功或失败消息。 已返回: 总是 示例: |
|
API 对象。 已返回: 总是 |
|
来自服务器的 JSON 解析响应。 已返回: 总是 |