Übernahme aus privaten Projekt.
This commit is contained in:
19
roles/trixie_migration/tasks/backup-dirs.yml
Normal file
19
roles/trixie_migration/tasks/backup-dirs.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
- name: Sichere Verzeichnisse
|
||||
become: true
|
||||
ansible.builtin.command:
|
||||
cmd: >
|
||||
tar
|
||||
--create
|
||||
--gzip
|
||||
--file {{ backup_host_dir }}/{{ item }}.tar.gz
|
||||
--preserve-permissions
|
||||
--same-owner
|
||||
--numeric-owner
|
||||
-C /
|
||||
{{ item }}
|
||||
args:
|
||||
creates: "{{ backup_host_dir }}/{{ item }}.tar.gz"
|
||||
tags: backup
|
||||
loop: "{{ backupdirs }}"
|
||||
when: ansible_facts.lsb.codename in ["bookworm", "bullseye"]
|
||||
|
||||
8
roles/trixie_migration/tasks/backup-etc.yml
Normal file
8
roles/trixie_migration/tasks/backup-etc.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
- name: Sichere /etc
|
||||
ansible.builtin.copy:
|
||||
src: /etc/
|
||||
dest: "{{ backup_host_dir }}/etc/"
|
||||
remote_src: yes
|
||||
mode: preserve
|
||||
when: ansible_facts.lsb.codename in ["bookworm", "bullseye"]
|
||||
|
||||
7
roles/trixie_migration/tasks/backup-home.yml
Normal file
7
roles/trixie_migration/tasks/backup-home.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
- name: Sichere /home/
|
||||
ansible.builtin.copy:
|
||||
src: /home/
|
||||
dest: "{{ backup_host_dir }}/home/"
|
||||
remote_src: yes
|
||||
mode: preserve
|
||||
when: ansible_facts.lsb.codename in ["bookworm", "bullseye"]
|
||||
9
roles/trixie_migration/tasks/backup-opt.yml
Normal file
9
roles/trixie_migration/tasks/backup-opt.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
- name: Sichere /opt
|
||||
ansible.builtin.copy:
|
||||
src: /opt
|
||||
dest: "{{ backup_host_dir }}/opt/"
|
||||
remote_src: yes
|
||||
mode: preserve
|
||||
become: true
|
||||
when: ansible_facts.lsb.codename in ["bookworm", "bullseye"]
|
||||
|
||||
16
roles/trixie_migration/tasks/config-dns.yml
Normal file
16
roles/trixie_migration/tasks/config-dns.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
- name: Setze DNS-Server auf Pi-hole für NetworkManager-Connection "preconfigured"
|
||||
become: true
|
||||
ansible.builtin.command:
|
||||
cmd: >
|
||||
nmcli connection modify "preconfigured"
|
||||
ipv4.dns "{{ dns_ip }}"
|
||||
ipv4.ignore-auto-dns yes
|
||||
tags: dns
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
- name: Aktiviere geänderte DNS-Einstellungen
|
||||
become: true
|
||||
ansible.builtin.command: nmcli connection up "preconfigured"
|
||||
tags: dns
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
6
roles/trixie_migration/tasks/create-backup-dirs.yml
Normal file
6
roles/trixie_migration/tasks/create-backup-dirs.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
- name: Erstelle Host-spezifische Backup-Verzeichnisse
|
||||
file:
|
||||
path: "{{ backup_host_dir }}/{{ item }}"
|
||||
state: directory
|
||||
loop: "{{backupdirs}}"
|
||||
when: ansible_facts.lsb.codename in ["bookworm", "bullseye"]
|
||||
4
roles/trixie_migration/tasks/debug.yml
Normal file
4
roles/trixie_migration/tasks/debug.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
- name: Zeige Systeminformationen
|
||||
debug:
|
||||
msg: "Host: {{ inventory_hostname }} | Codename: {{ ansible_facts.lsb.codename }}"
|
||||
|
||||
33
roles/trixie_migration/tasks/export.yml
Normal file
33
roles/trixie_migration/tasks/export.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
- name: Exportiere installierte Pakete als YAML
|
||||
shell: |
|
||||
echo "packages:" > "{{ packages_file }}"
|
||||
dpkg-query -W -f=' - ${Package}\n' | sort >> "{{ packages_file }}"
|
||||
args:
|
||||
executable: /usr/bin/bash
|
||||
tags: export
|
||||
when: ansible_facts.lsb.codename in ["bookworm", "bullseye"]
|
||||
|
||||
- name: Prüfe, ob packages.yml erstellt wurde
|
||||
ansible.builtin.stat:
|
||||
path: "{{ packages_file }}"
|
||||
register: packages_file_check
|
||||
tags: export
|
||||
when: ansible_facts.lsb.codename in ["bookworm", "bullseye"]
|
||||
|
||||
- name: Abbrechen, wenn packages.yml fehlt
|
||||
ansible.builtin.fail:
|
||||
msg: "FEHLER: packages.yml wurde nicht erstellt – Paketexport ist fehlgeschlagen."
|
||||
tags: export
|
||||
when:
|
||||
- ansible_facts.lsb.codename in ["bookworm", "bullseye"]
|
||||
- not packages_file_check.stat.exists
|
||||
|
||||
- name: Abbrechen, wenn packages.yml leer ist
|
||||
ansible.builtin.fail:
|
||||
msg: "FEHLER: packages.yml wurde erstellt, ist aber leer."
|
||||
tags: export
|
||||
when:
|
||||
- ansible_facts.lsb.codename in ["bookworm", "bullseye"]
|
||||
- packages_file_check.stat.size | int == 0
|
||||
|
||||
|
||||
49
roles/trixie_migration/tasks/install.yml
Normal file
49
roles/trixie_migration/tasks/install.yml
Normal file
@@ -0,0 +1,49 @@
|
||||
- name: Kopiere packages.yml auf Trixie
|
||||
ansible.builtin.copy:
|
||||
src: "{{ packages_file }}"
|
||||
dest: "/tmp/packages.yml"
|
||||
remote_src: no # Quelle liegt auf Control-Host
|
||||
tags: install
|
||||
|
||||
- name: Prüfe, ob packages.yml auf Trixie existiert
|
||||
become: true
|
||||
stat:
|
||||
path: /tmp/packages.yml
|
||||
tags: install
|
||||
register: pkgfile
|
||||
|
||||
- name: Lade Paketliste auf Trixie ein
|
||||
become: true
|
||||
slurp:
|
||||
src: /tmp/packages.yml
|
||||
register: packages_yml
|
||||
tags: install
|
||||
when: pkgfile.stat.exists
|
||||
|
||||
- name: Konvertiere Paketliste in Variablen
|
||||
set_fact:
|
||||
packages_data: "{{ packages_yml.content | b64decode | from_yaml }}"
|
||||
tags: install
|
||||
when: pkgfile.stat.exists
|
||||
|
||||
- name: Lese Paketliste ein und ersetze exa durch eza
|
||||
set_fact:
|
||||
packages_data_fixed: "{{ packages_data.packages | map('regex_replace', '^exa$', 'eza') | list }}"
|
||||
tags: install
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
- name: Lese Paketliste ein und ersetze neofetch durch fastfetch
|
||||
set_fact:
|
||||
packages_data_fixed: "{{ packages_data_fixed| map('regex_replace', '^neofetch$', 'fastfetch') | list }}"
|
||||
tags: install
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
- name: Installiere gesicherte Pakete
|
||||
apt:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
become: true
|
||||
loop: "{{ packages_data_fixed }}"
|
||||
ignore_errors: yes
|
||||
tags: install
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
15
roles/trixie_migration/tasks/main.yml
Normal file
15
roles/trixie_migration/tasks/main.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
- include_vars: "roles/trixie_migration/vars/backup-dirs.yml"
|
||||
|
||||
# Phase 1: bookworm sichern
|
||||
- import_tasks: debug.yml
|
||||
- import_tasks: create-backup-dirs.yml
|
||||
- import_tasks: export.yml
|
||||
- import_tasks: backup-dirs.yml
|
||||
|
||||
#Phase 2: Trixie aufsetzen
|
||||
- import_tasks: config-dns.yml
|
||||
- import_tasks: upgrade.yml
|
||||
- import_tasks: mounttank.yml
|
||||
- import_tasks: install.yml
|
||||
- import_tasks: restore-dirs.yml
|
||||
- import_tasks: reboot.yml
|
||||
36
roles/trixie_migration/tasks/mounttank.yml
Normal file
36
roles/trixie_migration/tasks/mounttank.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
- name: create tank dir
|
||||
become: true
|
||||
file:
|
||||
path: "/tank"
|
||||
state: directory
|
||||
tags: mount
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
- name: Installiere nfs-common
|
||||
apt:
|
||||
name:
|
||||
- nfs-common
|
||||
- eza
|
||||
state: present
|
||||
become: true
|
||||
tags: mount
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
|
||||
- name: Ensure /tank is mounted
|
||||
become: true
|
||||
ansible.posix.mount:
|
||||
path: /tank
|
||||
src: "{{nas_ip}}:/mnt/md0/public"
|
||||
fstype: "nfs"
|
||||
opts: "defaults"
|
||||
state: mounted
|
||||
tags: mount
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
- name: Facts aktualisieren
|
||||
setup:
|
||||
filter: ansible_mounts
|
||||
tags: mount
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
7
roles/trixie_migration/tasks/reboot.yml
Normal file
7
roles/trixie_migration/tasks/reboot.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
- name: Neustart des neuen Systems.
|
||||
ansible.builtin.reboot:
|
||||
reboot_timeout: 300
|
||||
msg: " Neustart des Trixie Systems wird durchgeführt."
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
26
roles/trixie_migration/tasks/restore-dirs.yml
Normal file
26
roles/trixie_migration/tasks/restore-dirs.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
- name: Verzeichnisse wiederherstellen
|
||||
become: true
|
||||
ansible.builtin.command:
|
||||
cmd: >
|
||||
tar
|
||||
--extract
|
||||
--gzip
|
||||
--file {{ backup_host_dir }}/{{ item }}.tar.gz
|
||||
--preserve-permissions
|
||||
--same-owner
|
||||
--numeric-owner
|
||||
-C /
|
||||
loop:
|
||||
- /home
|
||||
- /opt
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
- name: Eigentümer für /home/pi korrigieren
|
||||
file:
|
||||
path: /home/pi
|
||||
owner: pi
|
||||
group: pi
|
||||
recurse: yes
|
||||
tags: restore
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
9
roles/trixie_migration/tasks/restore-etc.yml
Normal file
9
roles/trixie_migration/tasks/restore-etc.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
- name: /etc wiederherstellen (vorsichtig!)
|
||||
synchronize:
|
||||
src: "{{ restore_etc_src }}/"
|
||||
dest: /etc/
|
||||
recursive: yes
|
||||
delete: no
|
||||
rsync_opts:
|
||||
- "--info=progress2"
|
||||
|
||||
17
roles/trixie_migration/tasks/restore-home.yml
Normal file
17
roles/trixie_migration/tasks/restore-home.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
- name: /home/pi wiederherstellen
|
||||
ansible.builtin.copy:
|
||||
src: "{{ backup_host_dir }}/home/"
|
||||
dest: /home/
|
||||
remote_src: yes
|
||||
mode: preserve
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
- name: Eigentümer für /home/pi korrigieren
|
||||
file:
|
||||
path: /home/pi
|
||||
owner: pi
|
||||
group: pi
|
||||
recurse: yes
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
|
||||
|
||||
8
roles/trixie_migration/tasks/restore-opt.yml
Normal file
8
roles/trixie_migration/tasks/restore-opt.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
- name: /opt wiederherstellen
|
||||
ansible.builtin.copy:
|
||||
src: "{{ backup_host_dir }}/opt/"
|
||||
dest: /opt/
|
||||
remote_src: yes
|
||||
mode: preserve
|
||||
become: true
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
7
roles/trixie_migration/tasks/upgrade.yml
Normal file
7
roles/trixie_migration/tasks/upgrade.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
- name: Update & dist-upgrade
|
||||
apt:
|
||||
update_cache: yes
|
||||
upgrade: dist
|
||||
become: true
|
||||
tags: upgrade
|
||||
when: ansible_facts.lsb.codename == "trixie"
|
||||
5
roles/trixie_migration/vars/backup-dirs.yml
Normal file
5
roles/trixie_migration/vars/backup-dirs.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
backupdirs:
|
||||
- /home
|
||||
- /etc
|
||||
- /opt
|
||||
|
||||
15
roles/trixie_migration/vars/main.yml
Normal file
15
roles/trixie_migration/vars/main.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
# IP
|
||||
dns_ip: "192.168.178.60"
|
||||
nas_ip: "192.168.178.36"
|
||||
|
||||
#Netzwerkverbindung
|
||||
nm_connection_name: "netplan-wlan0-<ssid>"
|
||||
# Pfade
|
||||
|
||||
backup_base: /tank/trixie
|
||||
backup_host_dir: "{{ backup_base }}/{{ inventory_hostname }}"
|
||||
restore_home_src: "{{ backup_host_dir }}/home/pi"
|
||||
restore_etc_src: "{{ backup_host_dir }}/etc"
|
||||
packages_file: "{{ backup_host_dir }}/packages.yml"
|
||||
|
||||
|
||||
9
trixi-migration.yml
Normal file
9
trixi-migration.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
- name: Raspberry Pi Backup oder Restore je nach OS-Codename
|
||||
hosts: "{{ target }}"
|
||||
become: yes
|
||||
gather_facts: yes
|
||||
remote_user: pi
|
||||
roles:
|
||||
- trixie_migration
|
||||
|
||||
Reference in New Issue
Block a user