Skip to content

Commit

Permalink
Fix for #31
Browse files Browse the repository at this point in the history
  • Loading branch information
octplane committed Mar 5, 2023
1 parent a400b37 commit d87dd29
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ callback_plugins= ./callbacks
inventory = hosts
interpreter_python = /usr/bin/python3
stdout_callback = anstomlog
display_ok_hosts = False

# Silence
retry_files_enabled = False
30 changes: 17 additions & 13 deletions callbacks/anstomlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
# Fields we will delete from the result
DELETABLE_FIELDS = [
'stdout', 'stdout_lines', 'rc', 'stderr', 'start', 'end', 'msg',
'_ansible_verbose_always', '_ansible_no_log', 'invocation', '_ansible_parsed',
'_ansible_item_result', '_ansible_ignore_errors', '_ansible_item_label']
'_ansible_verbose_always', '_ansible_no_log', 'invocation',
'_ansible_parsed', '_ansible_item_result', '_ansible_ignore_errors',
'_ansible_item_label']


def deep_serialize(data, indent=0):
Expand Down Expand Up @@ -337,7 +338,7 @@ def v2_runner_on_ok(self, result):
sys.stdout.write(" \n")
return

display_ok = self.get_option('display_ok_hosts')
display_ok = self.get_option("display_ok_hosts")
if not display_ok:
return

Expand Down Expand Up @@ -384,8 +385,14 @@ def _emit_line(self, lines, color=C.COLOR_OK):
self._display.display(line, color=color)

def v2_runner_on_unreachable(self, result):
self._emit_line('{} | UNREACHABLE!: {}'.format(
self._host_string(result), result._result.get('msg', '')), color=C.COLOR_CHANGED)
line = '{} | UNREACHABLE!: {}'.format(
self._host_string(result), result._result.get('msg', ''))


if result._task.ignore_unreachable:
line = line + " | IGNORED"

self._emit_line(line, C.COLOR_SKIP)

def v2_runner_on_skipped(self, result):
display_skipped = self.get_option('display_skipped_hosts')
Expand Down Expand Up @@ -414,23 +421,20 @@ def v2_playbook_on_stats(self, stats):
for h in hosts:
t = stats.summarize(h)

self._emit_line(u"%s : %s %s %s %s" % (
self._emit_line(u"%s : %s %s %s %s %s %s %s" % (
hostcolor(h, t),
colorize(u'ok', t['ok'], C.COLOR_OK),
colorize(u'changed', t['changed'], C.COLOR_CHANGED),
colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE),
colorize(u'failed', t['failures'], C.COLOR_ERROR)))
colorize(u'failed', t['failures'], C.COLOR_ERROR),
colorize(u'skipped', t['skipped'], C.COLOR_SKIP),
colorize(u'rescued', t['rescued'], C.COLOR_OK),
colorize(u'ignored', t['ignored'], C.COLOR_WARN)))

def __init__(self, *args, **kwargs):
super(CallbackModule, self).__init__(*args, **kwargs)
self.task_started = datetime.now()
self.task_start_preamble = None
# python2 only
try:
reload(sys).setdefaultencoding('utf8')
# pylint: disable=W0702
except:
pass


if __name__ == '__main__':
Expand Down
3 changes: 3 additions & 0 deletions hosts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ localhost ansible_connection=local

[third]
127.0.0.1 ansible_connection=localhost

[unreach]
1.2.3.4
4 changes: 2 additions & 2 deletions test-2.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: "Test single execution"
hosts: localhost
hosts: first,second
tasks:
- command: "ls ."
- command: "ls ."
6 changes: 6 additions & 0 deletions test-31.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: "Test single execution"
hosts: unreach
ignore_unreachable: true
tasks:
- command: "ls ."
2 changes: 1 addition & 1 deletion test-4.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: "Test case for issue unicode"
hosts: first
hosts: first,
tasks:
- debug:
msg: "Ansible est ÉLÉGANT!"
Expand Down

0 comments on commit d87dd29

Please sign in to comment.