diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py index 2190b3462f3..dcf123168da 100644 --- a/lib/ansible/module_utils/basic.py +++ b/lib/ansible/module_utils/basic.py @@ -136,10 +136,10 @@ except ImportError: try: import simplejson as json except ImportError: - print('{"msg": "Error: ansible requires the stdlib json or simplejson module, neither was found!", "failed": true}') + print('\n{"msg": "Error: ansible requires the stdlib json or simplejson module, neither was found!", "failed": true}') sys.exit(1) except SyntaxError: - print('{"msg": "SyntaxError: probably due to installed simplejson being for a different python version", "failed": true}') + print('\n{"msg": "SyntaxError: probably due to installed simplejson being for a different python version", "failed": true}') sys.exit(1) HAVE_SELINUX=False @@ -574,7 +574,7 @@ class AnsibleModule(object): except Exception: e = get_exception() # Use exceptions here because it isn't safe to call fail_json until no_log is processed - print('{"failed": true, "msg": "Module alias error: %s"}' % str(e)) + print('\n{"failed": true, "msg": "Module alias error: %s"}' % str(e)) sys.exit(1) # Save parameter values that should never be logged @@ -1497,7 +1497,7 @@ class AnsibleModule(object): params = json.loads(buffer.decode('utf-8')) except ValueError: # This helper used too early for fail_json to work. - print('{"msg": "Error: Module unable to decode valid JSON on stdin. Unable to figure out what parameters were passed", "failed": true}') + print('\n{"msg": "Error: Module unable to decode valid JSON on stdin. Unable to figure out what parameters were passed", "failed": true}') sys.exit(1) if sys.version_info < (3,): @@ -1508,7 +1508,7 @@ class AnsibleModule(object): self.constants = params['ANSIBLE_MODULE_CONSTANTS'] except KeyError: # This helper used too early for fail_json to work. - print('{"msg": "Error: Module unable to locate ANSIBLE_MODULE_ARGS and ANSIBLE_MODULE_CONSTANTS in json data from stdin. Unable to figure out what parameters were passed", "failed": true}') + print('\n{"msg": "Error: Module unable to locate ANSIBLE_MODULE_ARGS and ANSIBLE_MODULE_CONSTANTS in json data from stdin. Unable to figure out what parameters were passed", "failed": true}') sys.exit(1) def _log_to_syslog(self, msg): @@ -1700,7 +1700,7 @@ class AnsibleModule(object): kwargs['invocation'] = {'module_args': self.params} kwargs = remove_values(kwargs, self.no_log_values) self.do_cleanup_files() - print(self.jsonify(kwargs)) + print('\n%s' % self.jsonify(kwargs)) sys.exit(0) def fail_json(self, **kwargs): @@ -1712,7 +1712,7 @@ class AnsibleModule(object): kwargs['invocation'] = {'module_args': self.params} kwargs = remove_values(kwargs, self.no_log_values) self.do_cleanup_files() - print(self.jsonify(kwargs)) + print('\n%s' % self.jsonify(kwargs)) sys.exit(1) def fail_on_missing_params(self, required_params=None): diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py index 7a8ee2b4bc8..5ac2aba59d2 100644 --- a/lib/ansible/plugins/action/__init__.py +++ b/lib/ansible/plugins/action/__init__.py @@ -240,7 +240,8 @@ class ActionBase(with_metaclass(ABCMeta, object)): raise AnsibleConnectionFailure(output) try: - rc = self._connection._shell.join_path(result['stdout'].strip(), u'').splitlines()[-1] + stdout_parts = result['stdout'].strip().split('%s=' % basefile, 1) + rc = self._connection._shell.join_path(stdout_parts[-1], u'').splitlines()[-1] except IndexError: # stdout was empty or just space, set to / to trigger error in next if rc = '/' diff --git a/lib/ansible/plugins/shell/__init__.py b/lib/ansible/plugins/shell/__init__.py index effbddd58ee..6b0ed98d1de 100644 --- a/lib/ansible/plugins/shell/__init__.py +++ b/lib/ansible/plugins/shell/__init__.py @@ -134,7 +134,7 @@ class ShellBase(object): basetmp = self.join_path(basetmpdir, basefile) cmd = 'mkdir -p %s echo %s %s' % (self._SHELL_SUB_LEFT, basetmp, self._SHELL_SUB_RIGHT) - cmd += ' %s echo %s echo %s %s' % (self._SHELL_AND, self._SHELL_SUB_LEFT, basetmp, self._SHELL_SUB_RIGHT) + cmd += ' %s echo %s=%s echo %s %s' % (self._SHELL_AND, basefile, self._SHELL_SUB_LEFT, basetmp, self._SHELL_SUB_RIGHT) # change the umask in a subshell to achieve the desired mode # also for directories created with `mkdir -p`