mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Added file feature (#1525)
* Added file feature * Update plugins/modules/source_control/git_config.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/source_control/git_config.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/1021-git_config-custom-file.yaml Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
1faf8ef08b
commit
6c3a5cf9b1
2 changed files with 29 additions and 11 deletions
4
changelogs/fragments/1021-git_config-custom-file.yaml
Normal file
4
changelogs/fragments/1021-git_config-custom-file.yaml
Normal file
|
@ -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).
|
|
@ -27,7 +27,7 @@ description:
|
||||||
options:
|
options:
|
||||||
list_all:
|
list_all:
|
||||||
description:
|
description:
|
||||||
- List all settings (optionally limited to a given I(scope))
|
- List all settings (optionally limited to a given I(scope)).
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
name:
|
name:
|
||||||
|
@ -38,13 +38,19 @@ options:
|
||||||
description:
|
description:
|
||||||
- Path to a git repository for reading and writing values from a
|
- Path to a git repository for reading and writing values from a
|
||||||
specific repo.
|
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:
|
scope:
|
||||||
description:
|
description:
|
||||||
- Specify which scope to read/set values from. This is required
|
- Specify which scope to read/set values from.
|
||||||
when setting config values. If this is set to local, you must
|
- This is required when setting config values.
|
||||||
also specify the repo parameter. It defaults to system only when
|
- If this is set to C(local), you must also specify the C(repo) parameter.
|
||||||
not using I(list_all)=yes.
|
- If this is set to C(file), you must also specify the C(file) parameter.
|
||||||
choices: [ "local", "global", "system" ]
|
- It defaults to system only when not using I(list_all)=C(yes).
|
||||||
|
choices: [ "file", "local", "global", "system" ]
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- "Indicates the setting should be set/unset.
|
- "Indicates the setting should be set/unset.
|
||||||
|
@ -160,12 +166,16 @@ def main():
|
||||||
list_all=dict(required=False, type='bool', default=False),
|
list_all=dict(required=False, type='bool', default=False),
|
||||||
name=dict(type='str'),
|
name=dict(type='str'),
|
||||||
repo=dict(type='path'),
|
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']),
|
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']],
|
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']],
|
required_one_of=[['list_all', 'name']],
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
@ -207,6 +217,10 @@ def main():
|
||||||
if name:
|
if name:
|
||||||
args.append(name)
|
args.append(name)
|
||||||
|
|
||||||
|
if scope == 'file':
|
||||||
|
args.append('-f')
|
||||||
|
args.append(params['file'])
|
||||||
|
|
||||||
if scope == 'local':
|
if scope == 'local':
|
||||||
dir = params['repo']
|
dir = params['repo']
|
||||||
elif params['list_all'] and params['repo']:
|
elif params['list_all'] and params['repo']:
|
||||||
|
@ -243,10 +257,10 @@ def main():
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
if unset:
|
if unset:
|
||||||
args.insert(len(args) - 1, "--" + unset)
|
args.insert(len(args) - 1, "--" + unset)
|
||||||
cmd = ' '.join(args)
|
cmd = args
|
||||||
else:
|
else:
|
||||||
new_value_quoted = shlex_quote(new_value)
|
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
|
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)
|
(rc, out, err) = module.run_command(cmd, cwd=dir, ignore_invalid_cwd=False)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
|
Loading…
Reference in a new issue