I understand that you like to have Distributed Logging on Remote/Managed Nodes. Such can and needs to be implemented within the playbooks itself, see in example Generating a log file from within an Ansible playbook ...
Distributed Logs
It is assumed that the log directory (i.e. /var/log/ansible
) exists and the necessary permissions are given on the Remote Node. Furthermore, for this example, gather_facts: true
and the execution path is defined (i.e. by ROLE: "{{ playbook_dir.split('/')[2] }}"
).
- name: "Log applying role {{ ROLE }} with tags {{ ansible_run_tags }}"
lineinfile:
path: "/var/log/ansible/{{ ROLE }}/last.{{ ansible_date_time.year }}{{ ansible_date_time.month }}{{ ansible_date_time.day }}.log"
create: yes
line: "{{ ansible_date_time.weekday }} {{ ansible_date_time.month }} {{ ansible_date_time.day }} {{ ansible_date_time.time }} {{ ansible_date_time.tz }} {{ ansible_date_time.year }}, {{ ansible_run_tags }}, {{ ansible_user }}"
If provided in a playbook as the very last task it will write a log entry on the Remote Node if the execution hasn't failed before. By doing this, one can have information on Remote Node(s) if roles, playbooks, tasks, etc. where applied, when and by whom, etc.
In your case, you need to adopt the approach and modify and enhance it for your needs. Just adjust the information to be logged with the parameter line
. You'll probably have some of the tasks Return Values included and maybe proceed further with