mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Guard against a shell profile printing extraneous data
This commit is contained in:
@@ -136,10 +136,10 @@ except ImportError:
|
|||||||
try:
|
try:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
except ImportError:
|
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)
|
sys.exit(1)
|
||||||
except SyntaxError:
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
HAVE_SELINUX=False
|
HAVE_SELINUX=False
|
||||||
@@ -574,7 +574,7 @@ class AnsibleModule(object):
|
|||||||
except Exception:
|
except Exception:
|
||||||
e = get_exception()
|
e = get_exception()
|
||||||
# Use exceptions here because it isn't safe to call fail_json until no_log is processed
|
# 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)
|
sys.exit(1)
|
||||||
|
|
||||||
# Save parameter values that should never be logged
|
# Save parameter values that should never be logged
|
||||||
@@ -1497,7 +1497,7 @@ class AnsibleModule(object):
|
|||||||
params = json.loads(buffer.decode('utf-8'))
|
params = json.loads(buffer.decode('utf-8'))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# This helper used too early for fail_json to work.
|
# 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)
|
sys.exit(1)
|
||||||
|
|
||||||
if sys.version_info < (3,):
|
if sys.version_info < (3,):
|
||||||
@@ -1508,7 +1508,7 @@ class AnsibleModule(object):
|
|||||||
self.constants = params['ANSIBLE_MODULE_CONSTANTS']
|
self.constants = params['ANSIBLE_MODULE_CONSTANTS']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# This helper used too early for fail_json to work.
|
# 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)
|
sys.exit(1)
|
||||||
|
|
||||||
def _log_to_syslog(self, msg):
|
def _log_to_syslog(self, msg):
|
||||||
@@ -1700,7 +1700,7 @@ class AnsibleModule(object):
|
|||||||
kwargs['invocation'] = {'module_args': self.params}
|
kwargs['invocation'] = {'module_args': self.params}
|
||||||
kwargs = remove_values(kwargs, self.no_log_values)
|
kwargs = remove_values(kwargs, self.no_log_values)
|
||||||
self.do_cleanup_files()
|
self.do_cleanup_files()
|
||||||
print(self.jsonify(kwargs))
|
print('\n%s' % self.jsonify(kwargs))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def fail_json(self, **kwargs):
|
def fail_json(self, **kwargs):
|
||||||
@@ -1712,7 +1712,7 @@ class AnsibleModule(object):
|
|||||||
kwargs['invocation'] = {'module_args': self.params}
|
kwargs['invocation'] = {'module_args': self.params}
|
||||||
kwargs = remove_values(kwargs, self.no_log_values)
|
kwargs = remove_values(kwargs, self.no_log_values)
|
||||||
self.do_cleanup_files()
|
self.do_cleanup_files()
|
||||||
print(self.jsonify(kwargs))
|
print('\n%s' % self.jsonify(kwargs))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def fail_on_missing_params(self, required_params=None):
|
def fail_on_missing_params(self, required_params=None):
|
||||||
|
|||||||
@@ -240,7 +240,8 @@ class ActionBase(with_metaclass(ABCMeta, object)):
|
|||||||
raise AnsibleConnectionFailure(output)
|
raise AnsibleConnectionFailure(output)
|
||||||
|
|
||||||
try:
|
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:
|
except IndexError:
|
||||||
# stdout was empty or just space, set to / to trigger error in next if
|
# stdout was empty or just space, set to / to trigger error in next if
|
||||||
rc = '/'
|
rc = '/'
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ class ShellBase(object):
|
|||||||
basetmp = self.join_path(basetmpdir, basefile)
|
basetmp = self.join_path(basetmpdir, basefile)
|
||||||
|
|
||||||
cmd = 'mkdir -p %s echo %s %s' % (self._SHELL_SUB_LEFT, basetmp, self._SHELL_SUB_RIGHT)
|
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
|
# change the umask in a subshell to achieve the desired mode
|
||||||
# also for directories created with `mkdir -p`
|
# also for directories created with `mkdir -p`
|
||||||
|
|||||||
Reference in New Issue
Block a user