diff --git a/lib/ansible/module_utils/service.py b/lib/ansible/module_utils/service.py index 06ae8392a83..5957c4442a6 100644 --- a/lib/ansible/module_utils/service.py +++ b/lib/ansible/module_utils/service.py @@ -36,7 +36,7 @@ import select import shlex import subprocess -from ansible.module_utils.six import PY2, b +from ansible.module_utils.six import b from ansible.module_utils.common.text.converters import to_bytes, to_text @@ -187,12 +187,8 @@ def daemonize(module, cmd): if pid == 0: os.close(pipe[0]) - # if command is string deal with py2 vs py3 conversions for shlex if not isinstance(cmd, list): - if PY2: - cmd = shlex.split(to_bytes(cmd, errors=errors)) - else: - cmd = shlex.split(to_text(cmd, errors=errors)) + cmd = shlex.split(to_text(cmd, errors=errors)) # make sure we always use byte strings run_cmd = [] @@ -247,9 +243,6 @@ def daemonize(module, cmd): break return_data += to_bytes(data, errors=errors) - # Note: no need to specify encoding on py3 as this module sends the - # pickle to itself (thus same python interpreter so we aren't mixing - # py2 and py3) return pickle.loads(to_bytes(return_data, errors=errors)) diff --git a/lib/ansible/modules/service.py b/lib/ansible/modules/service.py index a94b8445bde..438aeb0e1a4 100644 --- a/lib/ansible/modules/service.py +++ b/lib/ansible/modules/service.py @@ -180,7 +180,7 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.locale import get_best_parsable_locale from ansible.module_utils.common.sys_info import get_platform_subclass from ansible.module_utils.service import fail_if_missing, is_systemd_managed -from ansible.module_utils.six import PY2, b +from ansible.module_utils.six import b class Service(object): @@ -285,14 +285,8 @@ class Service(object): os._exit(0) # Start the command - if PY2: - # Python 2.6's shlex.split can't handle text strings correctly - cmd = to_bytes(cmd, errors='surrogate_or_strict') - cmd = shlex.split(cmd) - else: - # Python3.x shex.split text strings. - cmd = to_text(cmd, errors='surrogate_or_strict') - cmd = [to_bytes(c, errors='surrogate_or_strict') for c in shlex.split(cmd)] + cmd = to_text(cmd, errors='surrogate_or_strict') + cmd = [to_bytes(c, errors='surrogate_or_strict') for c in shlex.split(cmd)] # In either of the above cases, pass a list of byte strings to Popen # chkconfig localizes messages and we're screen scraping so make