From 887456ab8e86b50f1e95f3e221ce4b756395e54c Mon Sep 17 00:00:00 2001 From: Ted Timmons Date: Tue, 21 Mar 2017 15:11:11 -0700 Subject: [PATCH] Fix stderr false return value (#22845) * ensure exit_json does not fail from stderr=False - do a little bit of safety-checking in exit_json to not try to .splitlines() on a boolean - remove the stderr=boolean from uri.py, this is the only spot that uses it (at least so obviously) - add unit tests that call exit_json. These are useless because the stderr parsing is in _execute_module and is difficult to mock; deleting these tests after the commit. * remove added unit tests per prev commit exit_json doesn't do the param parsing, that is buried deep inside _execute_module. --- lib/ansible/modules/network/basics/uri.py | 5 ++--- lib/ansible/plugins/action/__init__.py | 10 +++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/network/basics/uri.py b/lib/ansible/modules/network/basics/uri.py index 377d50a0ce5..cb1faf6ecb2 100644 --- a/lib/ansible/modules/network/basics/uri.py +++ b/lib/ansible/modules/network/basics/uri.py @@ -425,15 +425,14 @@ def main(): # and the filename already exists. This allows idempotence # of uri executions. if os.path.exists(creates): - module.exit_json(stdout="skipped, since %s exists" % creates, - changed=False, stderr=False, rc=0) + module.exit_json(stdout="skipped, since %s exists" % creates, changed=False, rc=0) if removes is not None: # do not run the command if the line contains removes=filename # and the filename do not exists. This allows idempotence # of uri executions. if not os.path.exists(removes): - module.exit_json(stdout="skipped, since %s does not exist" % removes, changed=False, stderr=False, rc=0) + module.exit_json(stdout="skipped, since %s does not exist" % removes, changed=False, rc=0) # Make the request resp, content, dest = uri(module, url, dest, body, body_format, method, diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 95343c2e696..987f49b05e1 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -514,7 +514,7 @@ class ActionBase(with_metaclass(ABCMeta, object)): 3 = its a directory, not a file 4 = stat module failed, likely due to not finding python ''' - x = "0" # unknown error has occured + x = "0" # unknown error has occurred try: remote_stat = self._execute_remote_stat(path, all_vars, follow=follow) if remote_stat['exists'] and remote_stat['isdir']: @@ -754,9 +754,13 @@ class ActionBase(with_metaclass(ABCMeta, object)): # pre-split stdout/stderr into lines if needed if 'stdout' in data and 'stdout_lines' not in data: - data['stdout_lines'] = data.get('stdout', u'').splitlines() + # if the value is 'False', a default won't catch it. + txt = data.get('stdout', None) or u'' + data['stdout_lines'] = txt.splitlines() if 'stderr' in data and 'stderr_lines' not in data: - data['stderr_lines'] = data.get('stderr', u'').splitlines() + # if the value is 'False', a default won't catch it. + txt = data.get('stderr', None) or u'' + data['stderr_lines'] = txt.splitlines() display.debug("done with _execute_module (%s, %s)" % (module_name, module_args)) return data