<===
2025-10-20 07:32:29
---
- name: Сбор ЛОГОВ за СЕГОДНЯ (find -mtime -1)
hosts: all
become: yes
gather_facts: yes
vars:
log_source: "/var/log/mysys"
local_dir: "./logs/collected/{{ inventory_hostname }}"
archive: "{{ ansible_date_time.date }}_logs.tar.gz"
tasks:
- name: 📁 Создать папку
file:
path: "{{ local_dir }}"
state: directory
delegate_to: localhost
- name: 🔍 Найти логи СЕГОДНЯ (с ПРОБЕЛАМИ!)
find:
paths: "{{ log_source }}"
patterns: '*.log'
age: -1h
register: logs
- name: 📦 Архив + копия
shell: tar -czf /tmp/{{ archive }} {{ logs.files | map(attribute='path') | list | join(' ') }}
when: logs.files | length > 0
- name: 💾 Сохранить локально
fetch:
src: "/tmp/{{ archive }}"
dest: "{{ local_dir }}/{{ archive }}"
flat: yes
when: logs.files | length > 0
- name: 🧹 Убрать tmp
file:
path: "/tmp/{{ archive }}"
state: absent
when: logs.files | length > 0
- name: ℹ️ Отчет
debug:
msg: "{{ inventory_hostname }}: {{ logs.files | length }} файлов в {{ local_dir }}/{{ archive }}"