diff --git a/src/molecule/provisioner/ansible_playbook.py b/src/molecule/provisioner/ansible_playbook.py index 9d6cd17c06..47d5b25616 100644 --- a/src/molecule/provisioner/ansible_playbook.py +++ b/src/molecule/provisioner/ansible_playbook.py @@ -20,6 +20,7 @@ """Ansible-Playbook Provisioner Module.""" import logging +import warnings from molecule import util @@ -103,12 +104,18 @@ def execute(self): LOG.warning("Skipping, %s action has no playbook." % self._config.action) return - self._config.driver.sanity_checks() - result = util.run_command(self._ansible_command, debug=self._config.debug) + # breakpoint() + with warnings.catch_warnings(record=True) as warns: + # warnings.simplefilter("ignore") + self._config.driver.sanity_checks() + result = util.run_command(self._ansible_command, debug=self._config.debug) + + # print(warns) if result.returncode != 0: util.sysexit_with_message( f"Ansible return code was {result.returncode}, command was: {result.args}", result.returncode, + warns=warns, ) return result.stdout diff --git a/src/molecule/util.py b/src/molecule/util.py index 892c337736..1fcdfff325 100644 --- a/src/molecule/util.py +++ b/src/molecule/util.py @@ -96,7 +96,10 @@ def sysexit(code: int = 1) -> NoReturn: def sysexit_with_message( - msg: str, code: int = 1, detail: Optional[MutableMapping] = None + msg: str, + code: int = 1, + detail: Optional[MutableMapping] = None, + warns: Optional[List[Warning]] = None, ) -> None: """Exit with an error message.""" # detail is usually a multi-line string which is not suitable for normal @@ -108,6 +111,9 @@ def sysexit_with_message( detail_str = str(detail) print(detail_str) LOG.critical(msg) + if warns: + for warn in warns: + LOG.warning(warn.__dict__['message'].args[0]) sysexit(code)