diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index a31b34faf0..5462b94628 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -655,7 +655,7 @@ class Runner(object): cmd = " || ".join(md5s) cmd = "%s; %s || (echo \"${rc} %s\")" % (test, cmd, path) - return utils.last_non_blank_line(self._low_level_exec_command(conn, cmd, tmp, sudoable=False)).split()[0] + return utils.last_non_blank_line(self._low_level_exec_command(conn, cmd, tmp, sudoable=False)) # ***************************************************** @@ -675,7 +675,7 @@ class Runner(object): cmd += ' && echo %s' % basetmp result = self._low_level_exec_command(conn, cmd, None, sudoable=False) - return utils.last_non_blank_line(result.split("\n"))[0].strip() + '/' + return utils.last_non_blank_line(result).strip() + '/' # ***************************************************** diff --git a/lib/ansible/utils.py b/lib/ansible/utils.py index 7b2ef864b9..2e1109adfe 100644 --- a/lib/ansible/utils.py +++ b/lib/ansible/utils.py @@ -412,7 +412,18 @@ def do_encrypt(result, encrypt, salt_size=None, salt=None): return result def last_non_blank_line(lines): - return lines + all_lines = lines.splitlines() + all_lines.reverse() + for line in all_lines: + if (len(line) > 0): + return line + + return "" # we shouldn't come here (no lines?) but let's pretend nothing happend + # We can't return all lines here because calling code expects only one + # line. + +def line_needs_filtering(line): + return line.startswith('#') or (len(line) == 0) def filter_leading_garbage(lines): return lines