diff options
author | Matt Martz <matt@sivel.net> | 2021-01-11 01:02:33 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-11 01:02:33 -0600 |
commit | 6ba066fc9e0e403b0c705cd39c6af824c07ea8a0 (patch) | |
tree | a49586c3a8b61f65674432918e18366460926118 | |
parent | b22d97b2c1cb03d1ab112196bd931ee83ef2485d (diff) | |
download | ansible-6ba066fc9e0e403b0c705cd39c6af824c07ea8a0.tar.gz |
[stable-2.10] Fix async interpreter parsing (#72636) (#72923)
Fixes #70690
(cherry picked from commit 83764ad)
-rw-r--r-- | changelogs/fragments/70690-async-interpreter.yml | 3 | ||||
-rw-r--r-- | lib/ansible/modules/async_wrapper.py | 13 | ||||
-rw-r--r-- | test/integration/targets/noexec/aliases | 3 | ||||
-rw-r--r-- | test/integration/targets/noexec/inventory | 1 | ||||
-rwxr-xr-x | test/integration/targets/noexec/runme.sh | 9 | ||||
-rw-r--r-- | test/integration/targets/noexec/test-noexec.yml | 8 |
6 files changed, 29 insertions, 8 deletions
diff --git a/changelogs/fragments/70690-async-interpreter.yml b/changelogs/fragments/70690-async-interpreter.yml new file mode 100644 index 0000000000..55a29f3c15 --- /dev/null +++ b/changelogs/fragments/70690-async-interpreter.yml @@ -0,0 +1,3 @@ +bugfixes: +- async - Fix Python 3 interpreter parsing from module by comparing with bytes + (https://github.com/ansible/ansible/issues/70690) diff --git a/lib/ansible/modules/async_wrapper.py b/lib/ansible/modules/async_wrapper.py index 640e74cf93..5379726ae6 100644 --- a/lib/ansible/modules/async_wrapper.py +++ b/lib/ansible/modules/async_wrapper.py @@ -21,7 +21,7 @@ import time import syslog import multiprocessing -from ansible.module_utils._text import to_text +from ansible.module_utils._text import to_text, to_bytes PY3 = sys.version_info[0] == 3 @@ -114,14 +114,11 @@ def _filter_non_json_lines(data): def _get_interpreter(module_path): - module_fd = open(module_path, 'rb') - try: + with open(module_path, 'rb') as module_fd: head = module_fd.read(1024) - if head[0:2] != '#!': + if head[0:2] != b'#!': return None - return head[2:head.index('\n')].strip().split(' ') - finally: - module_fd.close() + return head[2:head.index(b'\n')].strip().split(b' ') def _make_temp_dir(path): @@ -152,7 +149,7 @@ def _run_module(wrapped_cmd, jid, job_path): filtered_outdata = '' stderr = '' try: - cmd = shlex.split(wrapped_cmd) + cmd = [to_bytes(c, errors='surrogate_or_strict') for c in shlex.split(wrapped_cmd)] # call the module interpreter directly (for non-binary modules) # this permits use of a script for an interpreter on non-Linux platforms interpreter = _get_interpreter(cmd[0]) diff --git a/test/integration/targets/noexec/aliases b/test/integration/targets/noexec/aliases new file mode 100644 index 0000000000..66a77c7b29 --- /dev/null +++ b/test/integration/targets/noexec/aliases @@ -0,0 +1,3 @@ +shippable/posix/group2 +skip/docker +skip/macos diff --git a/test/integration/targets/noexec/inventory b/test/integration/targets/noexec/inventory new file mode 100644 index 0000000000..ab9b62c8bb --- /dev/null +++ b/test/integration/targets/noexec/inventory @@ -0,0 +1 @@ +not_empty # avoid empty empty hosts list warning without defining explicit localhost diff --git a/test/integration/targets/noexec/runme.sh b/test/integration/targets/noexec/runme.sh new file mode 100755 index 0000000000..ff7065583a --- /dev/null +++ b/test/integration/targets/noexec/runme.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -eux + +trap 'umount "${OUTPUT_DIR}/ramdisk"' EXIT + +mkdir "${OUTPUT_DIR}/ramdisk" +mount -t tmpfs -o size=32m,noexec,rw tmpfs "${OUTPUT_DIR}/ramdisk" +ANSIBLE_REMOTE_TMP="${OUTPUT_DIR}/ramdisk" ansible-playbook -i inventory "$@" test-noexec.yml diff --git a/test/integration/targets/noexec/test-noexec.yml b/test/integration/targets/noexec/test-noexec.yml new file mode 100644 index 0000000000..3c7d756b56 --- /dev/null +++ b/test/integration/targets/noexec/test-noexec.yml @@ -0,0 +1,8 @@ +- hosts: localhost + gather_facts: false + tasks: + - ping: + + - command: sleep 1 + async: 2 + poll: 1 |