community.general.git_config (0.1.1) — module

Read and write git configuration

Authors: Matthew Gamble (@djmattyg007), Marius Gedminas (@mgedmin)

preview | supported by community

Install collection

Install with ansible-galaxy collection install community.general:==0.1.1


Add to requirements.yml

  collections:
    - name: community.general
      version: 0.1.1

Description

The C(git_config) module changes git configuration by invoking 'git config'. This is needed if you don't want to use M(template) for the entire git config file (e.g. because you need to change just C(user.email) in /etc/.git/config). Solutions involving M(command) are cumbersome or don't work correctly in check mode.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Set some settings in ~/.gitconfig
- git_config:
    name: alias.ci
    scope: global
    value: commit
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- git_config:
    name: alias.st
    scope: global
    value: status
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Unset some settings in ~/.gitconfig
- git_config:
    name: alias.ci
    scope: global
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Or system-wide:
- git_config:
    name: alias.remotev
    scope: system
    value: remote -v
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- git_config:
    name: core.editor
    scope: global
    value: vim
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# scope=system is the default
- git_config:
    name: alias.diffc
    value: diff --cached
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- git_config:
    name: color.ui
    value: auto
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Make etckeeper not complain when invoked by cron
- git_config:
    name: user.email
    repo: /etc
    scope: local
    value: 'root@{{ ansible_fqdn }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Read individual values from git config
- git_config:
    name: alias.ci
    scope: global
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# scope: system is also assumed when reading values, unless list_all=yes
- git_config:
    name: alias.diffc
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Read all values from git config
- git_config:
    list_all: yes
    scope: global
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# When list_all=yes and no scope is specified, you get configuration from all scopes
- git_config:
    list_all: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Specify a repository to include local settings
- git_config:
    list_all: yes
    repo: /path/to/repo.git

Inputs

    
name:
    description:
    - The name of the setting. If no value is supplied, the value will be read from the
      config if it has been set.

repo:
    description:
    - Path to a git repository for reading and writing values from a specific repo.

scope:
    choices:
    - local
    - global
    - system
    description:
    - Specify which scope to read/set values from. This is required when setting config
      values. If this is set to local, you must also specify the repo parameter. It defaults
      to system only when not using I(list_all)=yes.

state:
    choices:
    - present
    - absent
    default: present
    description:
    - 'Indicates the setting should be set/unset. This parameter has higher precedence
      than I(value) parameter: when I(state)=absent and I(value) is defined, I(value)
      is discarded.'

value:
    description:
    - When specifying the name of a single setting, supply a value to set that setting
      to the given value.

list_all:
    default: 'no'
    description:
    - List all settings (optionally limited to a given I(scope))
    type: bool

Outputs

config_value:
  description: When list_all=no and value is not set, a string containing the value
    of the setting in name
  returned: success
  sample: vim
  type: str
config_values:
  description: When list_all=yes, a dict containing key/value pairs of multiple configuration
    settings
  returned: success
  sample:
    alias.diffc: diff --cached
    alias.remotev: remote -v
    color.ui: auto
    core.editor: vim
  type: dict