From 6c3a5cf9b198ab3be682b96a780090031827ab34 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Wed, 23 Dec 2020 04:17:24 +1300 Subject: [PATCH] Added file feature (#1525) * Added file feature * Update plugins/modules/source_control/git_config.py Co-authored-by: Felix Fontein * Update plugins/modules/source_control/git_config.py Co-authored-by: Felix Fontein * Update changelogs/fragments/1021-git_config-custom-file.yaml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- .../1021-git_config-custom-file.yaml | 4 +++ plugins/modules/source_control/git_config.py | 36 +++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 changelogs/fragments/1021-git_config-custom-file.yaml diff --git a/changelogs/fragments/1021-git_config-custom-file.yaml b/changelogs/fragments/1021-git_config-custom-file.yaml new file mode 100644 index 0000000000..f83a43fef2 --- /dev/null +++ b/changelogs/fragments/1021-git_config-custom-file.yaml @@ -0,0 +1,4 @@ +minor_changes: + - git_config - added parameter and scope ``file`` allowing user to change parameters in a custom file (https://github.com/ansible-collections/community.general/issues/1021). +bugfixes: + - git_config - using list instead of string as first parameter in the ``run_command()`` call (https://github.com/ansible-collections/community.general/issues/1021). diff --git a/plugins/modules/source_control/git_config.py b/plugins/modules/source_control/git_config.py index 66ef45f354..21c3af6802 100644 --- a/plugins/modules/source_control/git_config.py +++ b/plugins/modules/source_control/git_config.py @@ -27,7 +27,7 @@ description: options: list_all: description: - - List all settings (optionally limited to a given I(scope)) + - List all settings (optionally limited to a given I(scope)). type: bool default: 'no' name: @@ -38,13 +38,19 @@ options: description: - Path to a git repository for reading and writing values from a specific repo. + file: + description: + - Path to an adhoc git configuration file to be managed using the C(file) scope. + type: path + version_added: 2.0.0 scope: 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. - choices: [ "local", "global", "system" ] + - Specify which scope to read/set values from. + - This is required when setting config values. + - If this is set to C(local), you must also specify the C(repo) parameter. + - If this is set to C(file), you must also specify the C(file) parameter. + - It defaults to system only when not using I(list_all)=C(yes). + choices: [ "file", "local", "global", "system" ] state: description: - "Indicates the setting should be set/unset. @@ -160,12 +166,16 @@ def main(): list_all=dict(required=False, type='bool', default=False), name=dict(type='str'), repo=dict(type='path'), - scope=dict(required=False, type='str', choices=['local', 'global', 'system']), + file=dict(type='path'), + scope=dict(required=False, type='str', choices=['file', 'local', 'global', 'system']), state=dict(required=False, type='str', default='present', choices=['present', 'absent']), - value=dict(required=False) + value=dict(required=False), ), mutually_exclusive=[['list_all', 'name'], ['list_all', 'value'], ['list_all', 'state']], - required_if=[('scope', 'local', ['repo'])], + required_if=[ + ('scope', 'local', ['repo']), + ('scope', 'file', ['file']) + ], required_one_of=[['list_all', 'name']], supports_check_mode=True, ) @@ -207,6 +217,10 @@ def main(): if name: args.append(name) + if scope == 'file': + args.append('-f') + args.append(params['file']) + if scope == 'local': dir = params['repo'] elif params['list_all'] and params['repo']: @@ -243,10 +257,10 @@ def main(): if not module.check_mode: if unset: args.insert(len(args) - 1, "--" + unset) - cmd = ' '.join(args) + cmd = args else: new_value_quoted = shlex_quote(new_value) - cmd = ' '.join(args + [new_value_quoted]) + cmd = args + [new_value_quoted] try: # try using extra parameter from ansible-base 2.10.4 onwards (rc, out, err) = module.run_command(cmd, cwd=dir, ignore_invalid_cwd=False) except TypeError: