mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 03:11:24 -07:00
(cherry picked from commit 436bbb0077
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
248128f282
commit
451428af04
4 changed files with 42 additions and 7 deletions
|
@ -151,7 +151,6 @@ config_values:
|
|||
import os
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.six.moves import shlex_quote
|
||||
|
||||
|
||||
def main():
|
||||
|
@ -216,7 +215,7 @@ def main():
|
|||
# Run from root directory to avoid accidentally picking up any local config settings
|
||||
dir = "/"
|
||||
|
||||
(rc, out, err) = module.run_command(' '.join(args), cwd=dir)
|
||||
(rc, out, err) = module.run_command(args, cwd=dir, expand_user_and_vars=False)
|
||||
if params['list_all'] and scope and rc == 128 and 'unable to read config file' in err:
|
||||
# This just means nothing has been set at the given scope
|
||||
module.exit_json(changed=False, msg='', config_values={})
|
||||
|
@ -243,17 +242,16 @@ 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]
|
||||
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, expand_user_and_vars=False)
|
||||
except TypeError:
|
||||
# @TODO remove try/except when community.general drop support for 2.10.x
|
||||
if not os.path.isdir(dir):
|
||||
module.fail_json(msg="Cannot find directory '{0}'".format(dir))
|
||||
(rc, out, err) = module.run_command(cmd, cwd=dir)
|
||||
(rc, out, err) = module.run_command(cmd, cwd=dir, expand_user_and_vars=False)
|
||||
if err:
|
||||
module.fail_json(rc=rc, msg=err, cmd=cmd)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue