octplane / ansible_stdout_compact_logger Goto Github PK
View Code? Open in Web Editor NEWAnsible Stdout Compact Logger
License: MIT License
Ansible Stdout Compact Logger
License: MIT License
Hello,
it's beautiful plugin !
How to disable SKIPPED message if display_skipped_hosts is define to "False" on ansible.cfg.
Thanks
I am using Ansible 7.0.0 with Jenkins 2.381
When executing Ansible in a docker container the output of the default stdout-callback was uncolored in my Jenkins environment. The container is started without the "--tty" option of Docker.
When executing the same playbook on a console I get colored output.
With this plugin I get colored output on a normal console, but in Jenkins the output contains additional characters, that cannot be displayed. See the little boxes with question marks in the screenshot.
I would expect that in case color output is not supported in the environment (what is the case here obviously), the log output is just monochrome. Same behaviour as the default log output of Ansible.
Am I doing something wrong here or is it a bug or an unsupported use case?
Anyway, I like this plugin very much. Thanks for the great work!
I tried running this logger in a Python3 only environment.
First, I got an error that reload
was not found. I imported it with:
from importlib import reload
.
Then I got another error that sys
does not have a method called setdefaultencoding
. I located the line in the __init__
method that uses this and tried to do some magic there but I failed. I read that reload
and sys.setdefaultencoding
are deprecated and a bad practice in python3.
How could we get this module running for python 3?
Hello. i just updatet the callback script.
and it looks like i work.
but i'm starting to get this warrning now:
[WARNING]: Failure using method (v2_playbook_on_task_start) in callback plugin (<ansible.plugins.callback.anstomlog.CallbackModule object at 0x7f31f88241f0>): 'NoneType' object has no attribute 'get_name'
Thanks for creating the compact logger callback for ansible - this is a great way to save space! I did notice what appears to be a bug - on tasks that use with_items
, if a particular item is changed but others are not, it still reports the whole task as green when it should report it as orange. Moreover, it does not show the diff, even if --diff
is provided.
Here's an example task:
- name: template config files
template: src={{ item.src }} dest={{ item.dest }} mode={{ item.mode|default(omit) }}
with_items:
- { src: "calm_file.tmpl.j2", dest: "/usr/share/websvn/templates/calm/file.tmpl" }
- { src: "calm_index.tmpl.j2", dest: "/usr/share/websvn/templates/calm/index.tmpl" }
- { src: "config.php.j2", dest: "/etc/websvn/config.php" }
- { src: "index.html.j2", dest: "{{ www_root }}/index.html", mode: "0644" }
- { src: "svn_deb_conf.inc.j2", dest: "/etc/websvn/svn_deb_conf.inc" }
And here's the normal output:
TASK [servers/vcs : template config files] *****************
ok: [vcs] => (item={u'dest': u'/usr/share/websvn/templates/calm/file.tmpl', u'src': u'calm_file.tmpl.j2'})
ok: [vcs] => (item={u'dest': u'/usr/share/websvn/templates/calm/index.tmpl', u'src': u'calm_index.tmpl.j2'})
--- before: /etc/websvn/config.php
+++ after: dynamically generated
@@ -1,5 +1,6 @@
<?php
+// TEST LINE
// WebSVN - Subversion repository viewing via the web using PHP
// Copyright (C) 2004-2006 Tim Armes
//
changed: [vcs] => (item={u'dest': u'/etc/websvn/config.php', u'src': u'config.php.j2'})
ok: [vcs] => (item={u'dest': u'/var/www/index.html', u'src': u'index.html.j2', u'mode': u'0644'})
ok: [vcs] => (item={u'dest': u'/etc/websvn/svn_deb_conf.inc', u'src': u'svn_deb_conf.inc.j2'})
In comparison, here's the output with ansible_stdout_compact_logger enabled:
[2017-01-09 08:34:05.356555] servers/myserver : template config files | myserver | SUCCESS | 7090ms
I've been testing this with ansible 2.2.0.0.
Will be broken from version 2.11
.
rather than
[17:16:42] Create ca cert directory | 10.0.197.195 | SUCCESS | 765ms
10.0.198.55 | SUCCESS | 766ms
10.0.196.132 | SUCCESS | 885ms
It might be easier to read if it where
[17:16:42] Create ca cert directory
10.0.197.195 | SUCCESS | 765ms
10.0.198.55 | SUCCESS | 766ms
10.0.196.132 | SUCCESS | 885ms
(at least I find it much easier to read)
Otherwise, maybe, if all succeeded, something like
[17:16:42] Create ca cert directory | 10.0.197.195, 10.0.198.55, 10.0.196.132 | SUCCESS | 765ms
But of course this would scale well to lost of hosts. And where to put the timings?
I am constructing a big dict to interact with google cloud. When this dict gets printed I get a warning:
[WARNING]: Failure using method (v2_runner_on_ok) in callback plugin (<ansible.plugins.callback.anstomlog.CallbackModule object at 0x7ffb10714128>): not all arguments converted during
string formatting
Callback Exception:
File "/home/nikos/Projects/ansible/lib/ansible/executor/task_queue_manager.py", line 375, in send_callback
method(*new_args, **kwargs)
File "/home/nikos/Projects/Ethical Hacking/EN2720/ansible/lib/plugins/callback/anstomlog.py", line 327, in v2_runner_on_ok
self._emit_line(deep_serialize(result._result), color=color)
File "/home/nikos/Projects/Ethical Hacking/EN2720/ansible/lib/plugins/callback/anstomlog.py", line 73, in deep_serialize
"- %s: %s\n" % (key, deep_serialize(value, indent + 1))
File "/home/nikos/Projects/Ethical Hacking/EN2720/ansible/lib/plugins/callback/anstomlog.py", line 48, in deep_serialize
deep_serialize(item, indent)
File "/home/nikos/Projects/Ethical Hacking/EN2720/ansible/lib/plugins/callback/anstomlog.py", line 73, in deep_serialize
"- %s: %s\n" % (key, deep_serialize(value, indent + 1))
File "/home/nikos/Projects/Ethical Hacking/EN2720/ansible/lib/plugins/callback/anstomlog.py", line 77, in deep_serialize
string_form = "%s" % data
Would you also need the data that get printed?
actionable
callback does that by defaultI do not really know if this is an issue with this callback plugin, but when i do sth like:
for instance in "${instances[@]}"; do
ansible-playbook -i "$instance" playbook.yml &
done
I get tasks that should be run on one instance tagged as having been run on another. For example:
[05:33:20] twmn.holey-firefox : file | en2720-w11-buckeye -> localhost | SUCCESS | 249ms
[05:33:20] twmn.holey-firefox : template | en2720-w11-sea-turtle | SUCCESS | 1372ms
Above, the twmn.holey-firefox
role runs only for the en2720-w11-buckeye
instance. However the second line shows it as having been run against en2720-w11-sea-turtle
.
This is just an output issue as the tasks are run correctly.
Hi,
Thanks a lot for your work. I notice a small inconvenience using when I tried to print unicode characters. I got the problem only when I use the -v
ansible option.
For example, if you define the following playbook :
---
- name: "Test case for issue unicode"
hosts: first
tasks:
- name: "Error when using -v"
command: echo -e "\xe2\x98\xba\x0a"
This will produce the output in verbose mode :
[WARNING]: Failure using method (v2_runner_on_ok) in callback plugin (<ansible.plugins.callback.anstomlog.CallbackModule object at 0x7f21b4605c90>): 'ascii'
codec can't encode character u'\u263a' in position 0: ordinal not in range(128)
Once again, thanks for you work.
Patrick
The default behavior of Ansible is that you see the entire content of a loop element. This can be a lot and impractical. You can use loop_control.label
to change what should be displayed. But dump_loop_items
ignores the option and dumps the entire loop element.
Example:
---
- hosts: all
connection: local
gather_facts: false
tasks:
- set_fact:
myvar: "{{ item }}"
loop:
- name: aaa
- name: bbb
- name: ccc
loop_control:
extended: true
extended_allitems: false
label: "({{ ansible_loop.index }}/{{ ansible_loop.length }}) {{ item.name }}"
Plain Ansible output:
ansible-playbook test.yml -i localhost,
PLAY [all] *********************************************************************
TASK [set_fact] ****************************************************************
ok: [localhost] => (item=(1/3) aaa)
ok: [localhost] => (item=(2/3) bbb)
ok: [localhost] => (item=(3/3) ccc)
anstomlog (w/ dump_loop_items) output
ansible-playbook test.yml -i localhost,
[03:36:25] set_fact
localhost | SUCCESS - item={'ansible_facts': {'myvar': {'name': 'aaa'}}, 'item': {'name': 'aaa'}, 'ansible_loop': {'index': 1, 'index0': 0, 'first': True, 'last': False, 'length': 3, 'revindex': 3, 'revindex0': 2, 'nextitem': {'name': 'bbb'}}} | 30ms
localhost | SUCCESS - item={'ansible_facts': {'myvar': {'name': 'bbb'}}, 'item': {'name': 'bbb'}, 'ansible_loop': {'index': 2, 'index0': 1, 'first': False, 'last': False, 'length': 3, 'revindex': 2, 'revindex0': 1, 'nextitem': {'name': 'ccc'}, 'previtem': {'name': 'aaa'}}} | 30ms
localhost | SUCCESS - item={'ansible_facts': {'myvar': {'name': 'ccc'}}, 'item': {'name': 'ccc'}, 'ansible_loop': {'index': 3, 'index0': 2, 'first': False, 'last': True, 'length': 3, 'revindex': 1, 'revindex0': 0, 'previtem': {'name': 'bbb'}}} | 30ms
It would be really helpful to add more info as greater verbosity level is given.
The Callback ignore the environment variable ANSIBLE_DISPLAY_SKIPPED_HOSTS.
If I set in environenment with export ANSIBLE_DISPLAY_SKIPPED_HOSTS=false
or in ansible.cfg with display_skipped_hosts = false
all skipped hosts will be also displayed.
The "debug" module does not display anything when in a loop.
Example:
- hosts: all gather_facts: False tasks: - name: message loop debug: msg: "Hello {{item}}" with_items: - alice - bob
displays:
[16:20:18] message loop | some_host | SUCCESS | 45ms { - msg: All items completed }
Hi,
Very compact callback plugin, thanks.
I use actionable by default which filters messages without changes. When I need to visualize information I use a task like this one:
- debug:
msg: "{{variable}}"
changed_when: true
But with this callback debug message with changed_when true is always in ok state not on changed state.
Other little question, there is an option to filter ok state like in actionnable? When I launch playbook on many hosts there is too much ok state.
Thanks
To Be Implemented.
Running a script with error and the task-option ignore_unreachable: true
is set, the error is displayed in red letters and it continues, but in yml callback there is an addition ...ignoring
.
Final overview displays then also only "ok/changed/unreachable/failed" but no "ok/changed/unreachable/failed/skipped/rescued/ignored".
: ok=37 changed=17 unreachable=0 failed=0
: ok=37 changed=17 unreachable=0 failed=0 skipped=11 rescued=0 ignored=1
When I enable Ansible logging with log_path = ./ansible.log
, the log output is incomplete and is missing the tasks being executed. Could this be improved please, because we need the logs for auditing purposes?
STDOUT:
[08:45:47] Gathering Facts
↳ jump | SUCCESS | 991ms
[08:45:48] ↳ common/packages: Install epel repository
↳ jump | SUCCESS | 1.26s
[08:45:49] ↳ common/packages: Ensure common packages are installed
↳ jump | SUCCESS | 1.06s
[08:45:50] ↳ common/packages: Ensure forbidden packages are not installed
↳ jump | SUCCESS | 1.09s
ansible.log
:
2023-11-03 08:45:48,440 p=1285948 u=ansible n=ansible | ↳ jump | SUCCESS | 991ms
2023-11-03 08:45:49,720 p=1285948 u=ansible n=ansible | ↳ jump | SUCCESS | 1.26s
2023-11-03 08:45:50,781 p=1285948 u=ansible n=ansible | ↳ jump | SUCCESS | 1.06s
2023-11-03 08:45:51,877 p=1285948 u=ansible n=ansible | ↳ jump | SUCCESS | 1.09s
2023-11-03 08:45:52,176 p=1285948 u=ansible n=ansible | [ERROR]: User interrupted execution
ansible.cfg
:
[defaults]
ansible_managed = Ansible managed: {file}
force_color = True
force_valid_group_names = ignore
host_key_checking = False
inject_facts_as_vars = True
log_path = ./ansible.log
nocows = 1
remote_user = ansible
retry_files_enabled = False
roles_path = ./roles
callback_plugins = ./.config/plugins/callback
stdout_callback = anstomlog
[connection]
pipelining = True
[ssh_connection]
pipelining = True
When running with ansible 2.2.0.0, I do not see a message at the end of the compact output that shows the handlers that have been triggered. If I run with normal output, I see the handlers listed. Are triggered handlers not yet supported?
I just switched my ansible environment over to python3 and I'm hitting a bunch of errors in this logger. I'm not much of a python dev, so I'm kinda stuck at the moment. Is this lib compatible with python3? If not, would you consider porting it? I really love this logger! There is nothing else out there that even comes close.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.