From 2cb7390f5baa4ab393c7fcc649bb8bbc61683985 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Mon, 28 Oct 2024 18:24:29 +0100 Subject: [PATCH] sdfgds --- roles/mgrote_rsync/tasks/destination.yml | 74 +----------------- roles/mgrote_rsync/tasks/main.yml | 77 ++----------------- roles/mgrote_rsync/tasks/source.yml | 77 +++++++++++++++---- roles/mgrote_rsync/tasks/user.yml | 11 +++ .../mgrote_rsync/templates/rsync_mirror.sh.j2 | 4 + roles/mgrote_rsync/templates/syncoid.sh.j2 | 12 --- 6 files changed, 86 insertions(+), 169 deletions(-) create mode 100644 roles/mgrote_rsync/templates/rsync_mirror.sh.j2 delete mode 100644 roles/mgrote_rsync/templates/syncoid.sh.j2 diff --git a/roles/mgrote_rsync/tasks/destination.yml b/roles/mgrote_rsync/tasks/destination.yml index 410ae691..8d954da3 100644 --- a/roles/mgrote_rsync/tasks/destination.yml +++ b/roles/mgrote_rsync/tasks/destination.yml @@ -11,75 +11,7 @@ when: - sanoid_syncoid_destination_host -- name: Ensure user is added to sudoers - become: true - community.general.sudoers: - name: "users-sudo-{{ sanoid_user }}" - state: present +- name: template ssh public key + ansible.posix.authorized_key: user: "{{ sanoid_user }}" - commands: ALL - nopassword: true - when: - - sanoid_syncoid_destination_host - -- name: template syncoid.service - become: true - ansible.builtin.template: - src: "syncoid.service.j2" - dest: /etc/systemd/system/syncoid.service - owner: root - group: root - mode: "0644" - notify: - - systemctl daemon-reload - when: - - sanoid_syncoid_destination_host - -- name: template syncoid.sh - become: true - ansible.builtin.template: - src: "syncoid.sh.j2" - dest: /usr/bin/syncoid.sh - owner: root - group: root - mode: "0755" - when: - - sanoid_syncoid_destination_host - -- name: template syncoid_mail.service - become: true - ansible.builtin.template: - src: "syncoid_mail.service.j2" - dest: /etc/systemd/system/syncoid_mail.service - owner: root - group: root - mode: "0644" - notify: - - systemctl daemon-reload - when: - - sanoid_syncoid_destination_host - -- name: template syncoid.timer - become: true - ansible.builtin.template: - src: "syncoid.timer.j2" - dest: "/etc/systemd/system/syncoid.timer" - owner: root - group: root - mode: "0644" - notify: - - systemctl daemon-reload - when: - - sanoid_syncoid_destination_host - -- name: enable syncoid.timer - become: true - ansible.builtin.systemd: - name: "syncoid.timer" - enabled: true - masked: false - state: started - notify: - - systemctl daemon-reload - when: - - sanoid_syncoid_destination_host + key: "{{ sanoid_syncoid_ssh_pubkey }}" diff --git a/roles/mgrote_rsync/tasks/main.yml b/roles/mgrote_rsync/tasks/main.yml index 30e0bbd1..ce8d0170 100644 --- a/roles/mgrote_rsync/tasks/main.yml +++ b/roles/mgrote_rsync/tasks/main.yml @@ -1,78 +1,11 @@ --- -- name: include user tasks +- name: Include user tasks ansible.builtin.include_tasks: user.yml -- name: install packages from repo - become: true - ansible.builtin.apt: - name: - - mbuffer - - lzop - - libcapture-tiny-perl - - pv - - libconfig-ini-perl - - sanoid - state: present - -- name: Overwrite syncoid script from package - become: true - ansible.builtin.get_url: - url: https://raw.githubusercontent.com/jimsalterjrs/sanoid/master/syncoid - dest: /usr/bin/syncoid - mode: '0755' - owner: root - group: root - force: true - -- name: create sanoid directories - become: true - ansible.builtin.file: - path: "{{ item }}" - state: directory - owner: "{{ sanoid_user }}" - group: "{{ sanoid_user_group }}" - mode: "0700" - with_items: - - "/etc/sanoid" - - "/etc/sanoid/.ssh" - -- name: include snaps tasks - ansible.builtin.include_tasks: snaps.yml - when: - - sanoid_datasets is defined - - sanoid_templates is defined - - sanoid_snaps_enable is defined - - sanoid_snaps_enable - -- name: ensure timers are enabled - become: true - ansible.builtin.systemd: - state: started - name: "{{ item }}" - daemon_reload: true - masked: false - enabled: true - loop: - - sanoid.timer - -- name: ensure services are enabled - become: true - ansible.builtin.systemd: - name: "{{ item }}" - masked: false - enabled: true - loop: - - sanoid.service - - sanoid-prune.service - -- name: include source-host tasks +- name: Include source tasks ansible.builtin.include_tasks: source.yml - when: - - sanoid_syncoid_source_host is defined and sanoid_syncoid_source_host is true - - sanoid_syncoid_ssh_pubkey is defined + when: "source" in rsync_host -- name: include destination-host tasks +- name: Include destination tasks ansible.builtin.include_tasks: destination.yml - when: - - sanoid_syncoid_destination_host is defined and sanoid_syncoid_destination_host is true - - sanoid_syncoid_ssh_privkey is defined + when: "destination" in rsync_host diff --git a/roles/mgrote_rsync/tasks/source.yml b/roles/mgrote_rsync/tasks/source.yml index e3d605d2..63ca1161 100644 --- a/roles/mgrote_rsync/tasks/source.yml +++ b/roles/mgrote_rsync/tasks/source.yml @@ -1,20 +1,69 @@ --- -- name: template ssh public key +- name: Ensure packages are present become: true - ansible.posix.authorized_key: - user: "{{ sanoid_user }}" - key: "{{ sanoid_syncoid_ssh_pubkey }}" + ansible.builtin.package: + name: + - rsync state: present - when: - - sanoid_syncoid_source_host -- name: Ensure user is added to sudoers +- name: Ensure needed dirs exist become: true - community.general.sudoers: - name: "users-sudo-{{ sanoid_user }}" - state: present - user: "{{ sanoid_user }}" - commands: ALL - nopassword: true + ansible.builtin.file: + path: "{{ item }}" + state: directory + owner: "{{ sanoid_user }}" + group: "{{ sanoid_user_group }}" + mode: "0600" + with_items: + - "/etc/rsync_mirror/" + - "/etc/rsync_mirror/.ssh" + +- name: template syncoid.sh + become: true + ansible.builtin.template: + src: "syncoid.sh.j2" + dest: /usr/bin/syncoid.sh + owner: root + group: root + mode: "0755" when: - - sanoid_syncoid_source_host + - sanoid_syncoid_destination_host + +- name: Ensure services are present + become: true + ansible.builtin.template: + src: "{{ item }}.j2" + dest: "/etc/systemd/system/{{ item }}" + owner: root + group: root + mode: "0644" + notify: + - systemctl daemon-reload + loop: + - youtubedl.service + - youtubedl.timer + - youtubedl_mail.service + when: ytdl_active + +- name: Ensure timer unit is enabled + become: true + ansible.builtin.systemd: + name: youtubedl.timer + enabled: true + masked: false + state: started + notify: + - systemctl daemon-reload + when: ytdl_active + +- name: Ensure service units are enabled + become: true + ansible.builtin.systemd: + name: "{{ item }}" + masked: false + enabled: true + loop: + - youtubedl.service + - youtubedl.timer + - youtubedl_mail.service + when: ytdl_active diff --git a/roles/mgrote_rsync/tasks/user.yml b/roles/mgrote_rsync/tasks/user.yml index 541c63a2..ad929b2f 100644 --- a/roles/mgrote_rsync/tasks/user.yml +++ b/roles/mgrote_rsync/tasks/user.yml @@ -17,3 +17,14 @@ when: - sanoid_user_group is defined - sanoid_user is defined + +- name: Ensure user is added to sudoers + become: true + community.general.sudoers: + name: "users-sudo-{{ sanoid_user }}" + state: present + user: "{{ sanoid_user }}" + commands: ALL + nopassword: true + when: + - sanoid_syncoid_destination_host diff --git a/roles/mgrote_rsync/templates/rsync_mirror.sh.j2 b/roles/mgrote_rsync/templates/rsync_mirror.sh.j2 new file mode 100644 index 00000000..b6201dd4 --- /dev/null +++ b/roles/mgrote_rsync/templates/rsync_mirror.sh.j2 @@ -0,0 +1,4 @@ +#!/bin/bash +{{ file_header | default () }} + +rsync befehle.... diff --git a/roles/mgrote_rsync/templates/syncoid.sh.j2 b/roles/mgrote_rsync/templates/syncoid.sh.j2 deleted file mode 100644 index 68b2f752..00000000 --- a/roles/mgrote_rsync/templates/syncoid.sh.j2 +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -{{ file_header | default () }} - -# check if dest-dataset is mounted (sed: entferne 1. Zeile; awk: zeige nur yes/no; grep: RC1 when != yes) -{% for item in sanoid_syncoid_datasets_sync %} -# check if target dataset is mounted -/usr/sbin/zfs get mounted -H {{ item.destination_mount_check }} 2>&1 > /dev/null || echo "Pool not mounted!" -# check if source host is reachable -ping -c1 -W1 {{ item.source_host }} > /dev/null || {{ item.source_host }} not reachable! -# syncoid -export HOME=/root ; /usr/bin/syncoid --compress=zstd-fast --sshoption=StrictHostKeyChecking=no --delete-target-snapshots --use-hold --preserve-recordsize --sshkey "/etc/sanoid/.ssh/id_sanoid" --source-bwlimit {{ sanoid_syncoid_bwlimit }} {{ sanoid_user }}@{{ item.source_host }}:{{ item.source_dataset }} {{ item.destination_dataset }} -{% endfor %}