I need ansible logs per host (server) so I am using logs_play module in ansible.cfg.
callback_whitelist = log_plays
But the output is not human friendly. See an example log below:
Apr 10 2020 12:23:35 - OK - omitted
Apr 10 2020 12:23:46 - OK - {"results": [{"msg": "", "invocation": {"module_args": {"lock_timeout": 30, "update_cache": false, "disable_excludes": null, "exclude": [], "allow_downgrade": false, "disable_gpg_check": false, "conf_file": null, "use_backend": "auto", "state": "installed", "disablerepo": [], "releasever": null, "skip_broken": false, "autoremove": false, "download_dir": null, "enable_plugin": [], "installroot": "/", "install_weak_deps": true, "name": ["vim", "git"], "download_only": false, "bugfix": false, "list": null, "install_repoquery": true, "update_only": false, "disable_plugin": [], "enablerepo": [], "security": false, "validate_certs": true}}, "changed": false, "results": ["2:vim-enhanced-7.4.629-6.el7.x86_64 providing vim is already installed", "git-1.8.3.1-21.el7_7.x86_64 providing git is already installed"], "rc": 0, "_ansible_no_log": false, "failed": false, "item": ["vim", "git"], "ansible_loop_var": "item", "_ansible_item_label": ["vim", "git"]}], "msg": "All items completed", "changed": false}
Apr 10 2020 12:23:47 - SKIPPED - ...
You see that the second big line is shown as one line and it is not human readable. How to make it prettier line by line output ?
I know there is a setting to change the screen output format like stdout_callback. But how to do the same thing for logs in /var/log/ansible/hosts location ?
Best Answer
We use this in our
ansible.cfg
:This gives a more readable YAML output instead of JSON. If that doesn't suit you, there are a bunch of other callback plugins. See https://docs.ansible.com/ansible/latest/plugins/callback.html