How to register a separate file in each play in Ansible

Instead of a single log file defined in log_path, I want to have separate log files for each piece running in Ansible.

As far as I know, there is no built-in way to do this. Therefore, I am looking for smart hacks.

In particular, I want the log file to be generated in the [playlist name] format after the playbook has been launched. [date] .log

I found this thread in SO, but it does not meet my needs. An alias would be a solution if I could somehow rewrite the name of the play, and not just the date. The search solution would be fine if I could only copy the corresponding part from the main log file without any history up to the time of copying. Also, if you have many concurrent games, I don’t know how well this method will work.

Any hints / ideas? I thought I was creating a shell script that would be called inside the tutorial to somehow “extract” the relevant entries from the main journal and create a separate one. But I find that I am making it too complicated.

+1
source share
1

log_path ansible.cfg.

script: ansible-playbook-wrapper.sh

#!/bin/bash

export ANSIBLE_LOG_PATH=/var/log/ansible/playbook_$(echo $1 | cut -d . -f 1).log
ansible-playbook $@

alias ansible-playbook script :

alias ansible-playbook="/path/to/ansible-playbook-wrapper.sh"

, (, , ) :

sudo mkdir /var/log/ansible
sudo chmod 777 /var/log/ansible

, ansible-playbook dns_server.yml -u cobra -k, :

[cobra@ansible ~]$ ls /var/log/ansible
playbook-dns_server.log
playbook-some_other_playbook.log
playbook-even_more_plays.log
+3

Source: https://habr.com/ru/post/1627139/