mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix for run_command on py3 and enable lineinfile test on py3 (#17257)
* run_command needed a bit of tweaking to its string handling of arguments. * The run_command change fixes the last bit of lineinfile so we can enable its tests
This commit is contained in:
parent
9ac20e231d
commit
4a3a9c0f2d
2 changed files with 9 additions and 10 deletions
|
@ -139,7 +139,7 @@ from ansible.module_utils.pycompat24 import get_exception, literal_eval
|
||||||
from ansible.module_utils.six import (PY2, PY3, b, binary_type, integer_types,
|
from ansible.module_utils.six import (PY2, PY3, b, binary_type, integer_types,
|
||||||
iteritems, text_type, string_types)
|
iteritems, text_type, string_types)
|
||||||
from ansible.module_utils.six.moves import map, reduce
|
from ansible.module_utils.six.moves import map, reduce
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native, to_bytes, to_text
|
||||||
|
|
||||||
_NUMBERTYPES = tuple(list(integer_types) + [float])
|
_NUMBERTYPES = tuple(list(integer_types) + [float])
|
||||||
|
|
||||||
|
@ -2039,13 +2039,13 @@ class AnsibleModule(object):
|
||||||
shell = True
|
shell = True
|
||||||
elif isinstance(args, (binary_type, text_type)) and use_unsafe_shell:
|
elif isinstance(args, (binary_type, text_type)) and use_unsafe_shell:
|
||||||
shell = True
|
shell = True
|
||||||
elif isinstance(args, string_types):
|
elif isinstance(args, (binary_type, text_type)):
|
||||||
# On python2.6 and below, shlex has problems with text type
|
# On python2.6 and below, shlex has problems with text type
|
||||||
# On python3, shlex needs a text type.
|
# On python3, shlex needs a text type.
|
||||||
if PY2 and isinstance(args, text_type):
|
if PY2:
|
||||||
args = args.encode('utf-8')
|
args = to_bytes(args)
|
||||||
elif PY3 and isinstance(args, binary_type):
|
elif PY3:
|
||||||
args = args.decode('utf-8', errors='surrogateescape')
|
args = to_text(args, errors='surrogateescape')
|
||||||
args = shlex.split(args)
|
args = shlex.split(args)
|
||||||
else:
|
else:
|
||||||
msg = "Argument 'args' to run_command must be list or string"
|
msg = "Argument 'args' to run_command must be list or string"
|
||||||
|
@ -2055,9 +2055,9 @@ class AnsibleModule(object):
|
||||||
if prompt_regex:
|
if prompt_regex:
|
||||||
if isinstance(prompt_regex, text_type):
|
if isinstance(prompt_regex, text_type):
|
||||||
if PY3:
|
if PY3:
|
||||||
prompt_regex = prompt_regex.encode('utf-8', errors='surrogateescape')
|
prompt_regex = to_bytes(prompt_regex, errors='surrogateescape')
|
||||||
elif PY2:
|
elif PY2:
|
||||||
prompt_regex = prompt_regex.encode('utf-8')
|
prompt_regex = to_bytes(prompt_regex)
|
||||||
try:
|
try:
|
||||||
prompt_re = re.compile(prompt_regex, re.MULTILINE)
|
prompt_re = re.compile(prompt_regex, re.MULTILINE)
|
||||||
except re.error:
|
except re.error:
|
||||||
|
@ -2065,7 +2065,7 @@ class AnsibleModule(object):
|
||||||
|
|
||||||
# expand things like $HOME and ~
|
# expand things like $HOME and ~
|
||||||
if not shell:
|
if not shell:
|
||||||
args = [ os.path.expandvars(os.path.expanduser(x)) for x in args if x is not None ]
|
args = [ os.path.expanduser(os.path.expandvars(x)) for x in args if x is not None ]
|
||||||
|
|
||||||
rc = 0
|
rc = 0
|
||||||
msg = None
|
msg = None
|
||||||
|
|
|
@ -9,7 +9,6 @@ test_get_url
|
||||||
test_git
|
test_git
|
||||||
test_hg
|
test_hg
|
||||||
test_iterators
|
test_iterators
|
||||||
test_lineinfile
|
|
||||||
test_lookups
|
test_lookups
|
||||||
test_mysql_db
|
test_mysql_db
|
||||||
test_mysql_user
|
test_mysql_user
|
||||||
|
|
Loading…
Reference in a new issue