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 配置。如果您不想对整个 Git 配置文件使用 ansible.builtin.template(例如,因为您只需要更改 /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 版本开始,如果 | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持:完全支持 | 可以在 | |
| 支持:不支持 | 在 diff 模式下,将返回有关已更改内容(或可能需要在 | 
示例
- 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 }}'
返回值
常见的返回值已在此处记录,以下是此模块特有的字段
| 键 | 描述 | 
|---|---|
| 当 返回值:成功 示例: | 
