En esta entrada veremos como realizar backup de directorios utilizando ansible y sirviéndonos del modulo synchronize
esta receta descarga el contenido del directorio /etc del servidor utilizando rsync al servidor de ansible, una vez en el servidor de ansible lo comprime y realiza un rotado cada vez que se ejecuta de 12 semanas.
---
- hosts: all
tasks:
- name: Synchronization using rsync protocol (pull)
synchronize:
dest_port: 22
compress: yes
copy_links: no
links: no
mode: pull
src: /etc/
dest: /backup/{{ ansible_hostname }}
- archive:
path: /backup/{{ ansible_hostname }}/
dest: /backup/{{ ansible_hostname }}.{{ ansible_date_time.date }}.zip
remove: yes
format: zip
delegate_to: 127.0.0.1
- name: Ansible delete files older than 14 week
find:
paths: /backup/
age: 12w
register: files_to_delete
delegate_to: 127.0.0.1
- name: Ansible remove files older than a date
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ files_to_delete.files }}"
delegate_to: 127.0.0.1
- name: Ansible delete directory
file:
path: /backup/{{ ansible_hostname }}/
state: absent
delegate_to: 127.0.0.1
:wq!