Skip to content

Commit 1706d54

Browse files
authored
Workaround for no Exception issue for some failed ansible modules (#1786)
Currently pytest-ansible depends on the 'failed' or 'rc' field in the module result to determine whether the result is failed. Some ansible modules only have 'failed' field in their results. Due to an issue of pytest-ansible: ansible/pytest-ansible#47 The module results returned by pytest-ansible do not have such 'failed' field even when the ansible module failed. In this case, the `is_failed` property will always be `False`. Consequent, no exception will be raised when running some ansible module failed. This commit is a workaround for this issue. According to current ansible behavior, the 'exception' field will be available in failed ansible module result most of the time. When such field is observed in the result, we raise `RunAnsibleModuleFail` exception too. Signed-off-by: Xin Wang <xiwang5@microsoft.com>
1 parent 1d2fa82 commit 1706d54

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

tests/common/devices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def run_module(module_args, complex_args):
7878
logging.debug("{}::{}#{}: [{}] AnsibleModule::{} Result => {}"\
7979
.format(filename, function_name, line_number, self.hostname, self.module_name, json.dumps(res)))
8080

81-
if res.is_failed and not module_ignore_errors:
81+
if (res.is_failed or 'exception' in res) and not module_ignore_errors:
8282
raise RunAnsibleModuleFail("run module {} failed".format(self.module_name), res)
8383

8484
return res

0 commit comments

Comments
 (0)