community.general.git_config module – Update git configuration
Note
This module is part of the community.general collection (version 11.4.0).
You might already have this collection installed if you are using the ansible package.
It is not included in ansible-core.
To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.general.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.general.git_config.
Synopsis
- The community.general.git_config module changes git configuration by invoking - git config. This is needed if you do not want to use ansible.builtin.template for the entire git config file (for example because you need to change just- user.emailin- /etc/.git/config). Solutions involving ansible.builtin.command are cumbersome or do not work correctly in check mode.
Requirements
The below requirements are needed on the host that executes this module.
- git 
Parameters
| Parameter | Comments | 
|---|---|
| Specify if a value should replace the existing value(s) or if the new value should be added alongside other values with the same name. This option is only relevant when adding/replacing values. If  Choices: 
 | |
| Path to an adhoc git configuration file to be managed using the  | |
| The name of the setting. | |
| Path to a git repository for reading and writing values from a specific repo. | |
| Indicates the setting should be set/unset. This parameter has higher precedence than  Choices: 
 | |
| When specifying the name of a single setting, supply a value to set that setting to the given value. From community.general 11.0.0 on,  | 
Attributes
| Attribute | Support | Description | 
|---|---|---|
| Support: full | Can run in  | |
| Support: none | Returns details on what has changed (or possibly needs changing in  | 
Examples
- 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 }}'
