Matt Martz 2 weeks ago committed by GitHub
commit 2767df208f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1207,6 +1207,23 @@ class ActionBase(ABC):
data['deprecations'] = []
data['deprecations'].extend(self._discovery_deprecation_warnings)
if res['rc'] and data.get('_ansible_parsed') and not data.get('failed'):
data.setdefault('warnings', []).append(
f'The module ({self._task.resolved_action}) exited with a non-zero rc but was not marked as failed. '
'This may indicate a module execution failure or other module execution related issue. '
'Running with ANSIBLE_DEBUG=1 may provide more information.'
)
# data |= {
# 'failed': True,
# 'module_rc': res['rc'],
# 'msg': 'The module exited with a non-zero rc but was not marked as failed. This indicates a module execution failure.'
# }
# if 'module_stdout' not in data:
# data |= {
# 'module_stdout': res.get('stdout', ''),
# 'module_stderr': res.get('stderr', ''),
# }
# mark the entire module results untrusted as a template right here, since the current action could
# possibly template one of these values.
data = wrap_var(data)
@ -1247,8 +1264,11 @@ class ActionBase(ABC):
if 'exception' not in data and data['module_stdout'].startswith(u'Traceback'):
data['exception'] = data['module_stdout']
# The default
data['msg'] = "MODULE FAILURE"
if not data['module_stdout'].strip() and res.get('rc') == 0:
data['msg'] = "The module returned an empty response to stdout but exited with rc=0, this may indicate a misbehaving module."
else:
# The default
data['msg'] = "MODULE FAILURE"
# try to figure out if we are missing interpreter
if self._used_interpreter is not None:

@ -0,0 +1,2 @@
shippable/posix/group4
context/controller

@ -0,0 +1,53 @@
#!/usr/bin/python
# Copyright: Contributors to the Ansible project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import json
import sys
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import text_type
def main():
module = AnsibleModule(
argument_spec={
'rc': {
'type': 'int',
'default': 0,
},
'stdout': {
'type': 'raw',
'default': '{"msg": "Hello, World!"}',
},
'stderr': {
'type': 'raw',
'default': '',
},
'traceback': {
'type': 'bool',
'default': False,
},
}
)
if module.params['traceback']:
raise Exception('boom')
stdout = module.params['stdout']
stderr = module.params['stderr']
if not isinstance(stdout, text_type):
stdout = json.dumps(stdout, indent=4, sort_keys=True)
if not isinstance(stderr, text_type):
stderr = json.dumps(stderr, indent=4, sort_keys=True)
print('\n' + stdout, file=sys.stdout)
print('\n' + stderr, file=sys.stderr)
sys.exit(module.params['rc'])
if __name__ == '__main__':
main()

@ -0,0 +1,42 @@
- name: Nominal behavior
module_behavior:
register: nominal_behavior
- name: Missing stdout
module_behavior:
stdout: ''
register: missing_stdout
ignore_errors: true
- name: non-zero rc
module_behavior:
rc: 2
register: non_zero_rc
ignore_errors: true
- name: traceback
module_behavior:
traceback: true
register: traceback
ignore_errors: true
- name: behavior assertions
assert:
that:
- nominal_behavior is successful
- nominal_behavior.msg == 'Hello, World!'
- missing_stdout is failed
- missing_stdout.msg.splitlines()|first == empty_stdout
- non_zero_rc is successful
- non_zero_rc.warnings is defined
- non_zero_rc.warnings|select('search', 'exited with a non-zero rc') != []
# - non_zero_rc.module_rc == 2
# - non_zero_rc.module_stdout is defined
# - non_zero_rc.module_stderr is defined
- traceback is failed
- traceback.module_rc is not defined
vars:
empty_stdout: The module returned an empty response to stdout but exited with rc=0, this may indicate a misbehaving module.

@ -702,7 +702,7 @@ class TestActionBase(unittest.TestCase):
action_base._compute_environment_string.return_value = ''
action_base._connection.has_pipelining = False
action_base._make_tmp_path.return_value = '/the/tmp/path'
action_base._low_level_execute_command.return_value = dict(stdout='{"rc": 0, "stdout": "ok"}')
action_base._low_level_execute_command.return_value = dict(rc=0, stdout='{"rc": 0, "stdout": "ok"}')
self.assertEqual(action_base._execute_module(module_name=None, module_args=None), dict(_ansible_parsed=True, rc=0, stdout="ok", stdout_lines=['ok']))
self.assertEqual(
action_base._execute_module(

Loading…
Cancel
Save