Skip to content

Commit

Permalink
Improve how executed commands are logged
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jun 29, 2023
1 parent ab80427 commit 3859509
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/molecule/provisioner/ansible_playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""Ansible-Playbook Provisioner Module."""

import logging
import shlex
import warnings

from molecule import util
Expand Down Expand Up @@ -116,8 +117,10 @@ def execute(self, action_args=None):
result = util.run_command(self._ansible_command, debug=self._config.debug)

if result.returncode != 0:
from rich.markup import escape

util.sysexit_with_message(
f"Ansible return code was {result.returncode}, command was: {result.args}",
f"Ansible return code was {result.returncode}, command was: [dim]{escape(shlex.join(result.args))}[/dim]",
result.returncode,
warns=warns,
)
Expand Down
2 changes: 1 addition & 1 deletion src/molecule/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def sysexit_with_message(
if detail:
detail_str = safe_dump(detail) if isinstance(detail, dict) else str(detail)
print(detail_str)
LOG.critical(msg)
LOG.critical(msg, extra={"highlighter": False})

for warn in warns:
LOG.warning(warn.__dict__["message"].args[0])
Expand Down

0 comments on commit 3859509

Please sign in to comment.