community.general.git_config 模块 – 更新 git 配置
注意
此模块是 community.general 集合(版本 10.1.0)的一部分。
如果您使用的是 ansible
包,您可能已经安装了这个集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.general
。您需要进一步的要求才能使用此模块,请参阅 要求 了解详细信息。
要在 playbook 中使用它,请指定:community.general.git_config
。
概要
community.general.git_config 模块通过调用
git config
来更改 git 配置。如果您不想使用 ansible.builtin.template 来处理整个 git 配置文件(例如,因为您只需要更改 /etc/.git/config 中的user.email
),则需要这样做。涉及 ansible.builtin.command 的解决方案很麻烦或在检查模式下无法正常工作。
要求
在执行此模块的主机上需要以下要求。
git
参数
参数 |
注释 |
---|---|
指定值应替换现有值,还是应将新值与同名的其他值一起添加。 此选项仅在添加/替换值时相关。如果 选择
|
|
要使用 |
|
列出所有设置(可选地限制为给定的 此选项已弃用,将从 community.general 11.0.0 中删除。请改用 community.general.git_config_info。 选择
|
|
设置的名称。如果未提供值,则将从配置中读取该值(如果已设置)。 |
|
从特定仓库读取和写入值的 git 仓库的路径。 |
|
指定从中读取/设置值的范围。 设置配置值时,这是必需的。 如果将其设置为 如果将其设置为 默认情况下,仅当不使用 选择
|
|
指示应该设置/取消设置的配置。此参数的优先级高于 选择
|
|
当指定单个设置的名称时,提供一个值以将该设置设置为给定值。 从 community.general 11.0.0 版本开始,如果 |
属性
属性 |
支持 |
描述 |
---|---|---|
支持: 完全 |
可以在 |
|
支持: 无 |
当处于差异模式时,将返回已更改的内容的详细信息(或者可能需要在 |
示例
- name: Add a setting to ~/.gitconfig
community.general.git_config:
name: alias.ci
scope: global
value: commit
- name: Add a setting to ~/.gitconfig
community.general.git_config:
name: alias.st
scope: global
value: status
- name: Remove a setting from ~/.gitconfig
community.general.git_config:
name: alias.ci
scope: global
state: absent
- name: Add a setting to ~/.gitconfig
community.general.git_config:
name: core.editor
scope: global
value: vim
- name: Add a setting system-wide
community.general.git_config:
name: alias.remotev
scope: system
value: remote -v
- name: Add a setting to a system scope (default)
community.general.git_config:
name: alias.diffc
value: diff --cached
- name: Add a setting to a system scope (default)
community.general.git_config:
name: color.ui
value: auto
- name: Add several options for the same name
community.general.git_config:
name: push.pushoption
value: "{{ item }}"
add_mode: add
loop:
- merge_request.create
- merge_request.draft
- name: Make etckeeper not complaining when it is invoked by cron
community.general.git_config:
name: user.email
repo: /etc
scope: local
value: 'root@{{ ansible_fqdn }}'
返回值
常见的返回值已在此处记录 here,以下是此模块独有的字段
键 |
描述 |
---|---|
当 返回: 成功 示例: |