Separate ansible logs for distinct target nodes

OS_Version: RHEL9.6_Plow
python_version: 3.12.9
ansible-core: 2.18.6

It seems that the structure of ansible.cfg, particular as it relates to logging has changed markedly in the last few years, and I am trying to an up-to-date understanding of current SOP.

CONTEXT
I maintain many relatively recent ( < 6 year) bare-metal Dell boxes and would like to keep separate logs for each nodes. We are currently transitioning to using Ansible for our node configuration and away from Bundle. This is also a < 1-FTE allocation, just to put the staffing resources into context, and our primary responsibility is to keep our current ecosystem running smoothly on legacy code while the new Ansible framework is developed.

QUESTIONS

  • Is it possible have the Ansible log file for each machine be recorded locally on the target host and rather than as part of the LARGE log on the controller?
  • If not, is there a way to segment log information for each node into a different file via Ansible configuration itself on the controller?

This callback plugin may be what you’re after: community.general.log_plays callback – write playbook output to log file — Ansible Community Documentation

I use AWX but I’ll spare suggesting that since you said you had fewer than 1 FTE resource to dedicate to this. I haven’t used callback plugins myself but as far as I understand, you configure them in your ansible.cfg (more info: https://docs.ansible.com/ansible/latest/plugins/callback.html)

I have never heard of bundle before your post, and looking at the webpage left me in horror seeing it was written in Perl, and even more horror it was last updated in 2008. Good luck to you, sir.

2 Likes

Within my local ansible.cfg, which is derived from the template generated with ansible-config, does have:

[defaults]
# (path) File to which Ansible will log on the controller.
# When not set the logging is disabled.
;log_path=

# (boolean) Toggle Ansible logging to syslog on the target when it executes tasks. On Windows hosts, this will disable a newer style PowerShell modules from writing to the event log.
;no_target_syslog=False

# (string) Syslog facility to use when Ansible logs to the remote target.
;syslog_facility=LOG_USER

So at minimum, I need to specify the log_path in order to make logging work regardless of where I want to put the files in the end.


OK, so community.general.log_plays directs logging information on a 1-file per host basis to an alternative directory. Do wish the module name was a little less generic. :person_shrugging:

[defaults]
# Activate logging and store a copy of information in /tmp 
log_path=/tmp/ansible_logs

# need log_plays enabled in order to log on a per host basis
callbacks_enabled=community.general.log_plays

[callback_log_plays]
# where to put the per-host log files (shivers at use of "folder" on linux)
log_folder=/var/log/ansible/

Have I got this right, @mcen1?

Also, I appreciate the restraint on not pitching AWX. I would love something a bit more robust but only have so much mental bandwidth.

While @mcen1 has pointed out the per-host log file on controller solution, does anyone know how to do that but put the log file on the target instead?

There are the options

no_target_syslog = False
syslog_facility = /var/log/ansible/ansible.log

but I do not understand syslog well enough to understand whether it is working the way I want or expect it to.