homelab_automation/ansible/playbooks/backup-proxmox-config.yml
Bruno Charest 05087aa380
Some checks failed
Tests / Backend Tests (Python) (3.10) (push) Has been cancelled
Tests / Backend Tests (Python) (3.11) (push) Has been cancelled
Tests / Backend Tests (Python) (3.12) (push) Has been cancelled
Tests / Frontend Tests (JS) (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / All Tests Passed (push) Has been cancelled
Replace manual upsert logic with SQLite native upsert in Docker CRUD repositories, enhance Ansible backup playbook with better error handling and file permissions, add favicon endpoint, and improve playbook editor UI with syntax highlighting, lint integration, quality badges, and enhanced code editing features
2025-12-17 15:36:49 -05:00

90 lines
2.9 KiB
YAML

---
- name: Backup Serveurs Proxmox Configuration files
hosts: role_proxmox
become: true
gather_facts: true
vars:
category: backup
subcategory: configuration
backup_dir: /mnt/pve/SHARE_PROXMOX/backups
hostname: "{{ ansible_hostname }}"
timestamp: "{{ ansible_date_time.iso8601_basic_short }}"
backup_files_common:
- /etc/hostname
- /etc/hosts
- /etc/passwd
- /etc/group
- /etc/shadow
- /etc/sudoers
- /etc/ssh/sshd_config
tasks:
- name: Ensure backup root directory exists
ansible.builtin.file:
path: "{{ backup_dir }}"
state: directory
mode: '0755'
- name: Ensure host-specific backup directory exists
ansible.builtin.file:
path: "{{ backup_dir }}/{{ hostname }}"
state: directory
mode: '0700'
- name: Backup /etc essential configuration files
community.general.archive:
path: "{{ backup_files_common }}"
dest: "{{ backup_dir }}/{{ hostname }}/etc_backup_{{ timestamp }}.tar.gz"
format: gz
mode: '0644'
register: etc_backup_archive
failed_when: >-
etc_backup_archive is failed and
(
'No such file or directory' not in (etc_backup_archive.msg | default('')) and
'not found' not in (etc_backup_archive.msg | default(''))
)
- name: Ensure permissions on /etc backup archive
ansible.builtin.file:
path: "{{ backup_dir }}/{{ hostname }}/etc_backup_{{ timestamp }}.tar.gz"
state: file
mode: '0600'
when: etc_backup_archive is not failed
- name: Get root crontab
ansible.builtin.command: crontab -l
register: root_crontab
failed_when: false
changed_when: false
- name: Save root crontab to file
ansible.builtin.copy:
dest: "{{ backup_dir }}/{{ hostname }}/crontab_{{ timestamp }}.txt"
content: "{{ root_crontab.stdout | default('No crontab') }}"
mode: '0600'
- name: Export installed packages list
ansible.builtin.shell: |
{% if ansible_os_family == 'Debian' %}
dpkg --get-selections > {{ backup_dir }}/{{ hostname }}/packages_{{ timestamp }}.txt
{% elif ansible_os_family == 'RedHat' %}
rpm -qa > {{ backup_dir }}/{{ hostname }}/packages_{{ timestamp }}.txt
{% else %}
echo "Package export not implemented for {{ ansible_os_family }}" > {{ backup_dir }}/{{ hostname }}/packages_{{ timestamp }}.txt
{% endif %}
args:
executable: /bin/bash
changed_when: false
- name: List backup files
ansible.builtin.find:
paths: "{{ backup_dir }}/{{ hostname }}"
patterns: "*{{ timestamp }}*"
register: backup_files
- name: Display backup summary
ansible.builtin.debug:
msg: |
Backup completed for {{ inventory_hostname }}
Files created: {{ backup_files.files | map(attribute='path') | list }}