From 8ab23df606190036a72bd6d9d7202b9d358aeb6f Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 20:54:34 +0200 Subject: [PATCH 01/20] ff --- group_vars/pve.yml | 3 +++ roles/mgrote_cv4pve_autosnap/README.md | 11 ----------- roles/mgrote_cv4pve_autosnap/defaults/main.yml | 3 +++ roles/mgrote_cv4pve_autosnap/tasks/main.yml | 12 ++++++------ .../templates/cv4pve.service.j2 | 2 +- .../mgrote_cv4pve_autosnap/templates/cv4pve.timer.j2 | 1 - .../templates/cv4pve_mail.service.j2 | 1 - 7 files changed, 13 insertions(+), 20 deletions(-) delete mode 100644 roles/mgrote_cv4pve_autosnap/README.md diff --git a/group_vars/pve.yml b/group_vars/pve.yml index 6e8aa92b..63d8ca55 100644 --- a/group_vars/pve.yml +++ b/group_vars/pve.yml @@ -28,6 +28,9 @@ users: allow_sudo: true allow_passwordless_sudo: true +### cv4pve +cv4pve_version: "v1.14.8" + ### mgrote_apt_manage_packages apt_packages_extra: - ifupdown2 diff --git a/roles/mgrote_cv4pve_autosnap/README.md b/roles/mgrote_cv4pve_autosnap/README.md deleted file mode 100644 index 2238a007..00000000 --- a/roles/mgrote_cv4pve_autosnap/README.md +++ /dev/null @@ -1,11 +0,0 @@ -## mgrote.cv4pve - -### Beschreibung -Installiert [cv4pve-autosnap](https://github.com/Corsinvest/cv4pve-autosnap). -Legt einen systemd-timer. - -### getestet auf -- [x] ProxMox 7* - -### Variablen + Defaults -- see [defaults](./defaults/main.yml) diff --git a/roles/mgrote_cv4pve_autosnap/defaults/main.yml b/roles/mgrote_cv4pve_autosnap/defaults/main.yml index 7445698c..2a897263 100644 --- a/roles/mgrote_cv4pve_autosnap/defaults/main.yml +++ b/roles/mgrote_cv4pve_autosnap/defaults/main.yml @@ -12,3 +12,6 @@ cv4pve_keep_snapshots: 3 # under which user the script is run cv4pve_user_group: cv4pve cv4pve_user: cv4pve +# url +cv4pve_dl_link: https://github.com/Corsinvest/cv4pve-autosnap/releases/download/{{ cv4pve_version }}/cv4pve-autosnap-linux-x64.zip +cv4pve_version: "v1.14.8" diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index 9c9c6f6f..187deb59 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -2,7 +2,6 @@ - name: include user tasks ansible.builtin.include_tasks: user.yml - - name: create directories become: true ansible.builtin.file: @@ -17,18 +16,19 @@ - name: download archives become: true - ansible.builtin.get_url: - url: "{{ cv4pve_dl_link }}" - dest: /tmp/cv4pve/cv4pve-autosnap-linux-x64.zip + ansible.builtin.unarchive: + src: "{{ cv4pve_dl_link }}" + dest: /tmp/cv4pve/cv4pve-autosnap-linux-x64-{{ cv4pve_version }}.zip mode: '0775' owner: "{{ cv4pve_user }}" group: "{{ cv4pve_user_group }}" + remote_src: yes - name: extract archives become: true ansible.builtin.unarchive: - src: /tmp/cv4pve/cv4pve-autosnap-linux-x64.zip - dest: /usr/local/bin/cv4pve + src: /tmp/cv4pve/cv4pve-autosnap-linux-x64-{{ cv4pve_version }}.zip + dest: /usr/local/bin/cv4pve-{{ cv4pve_version }} remote_src: true mode: a+x owner: "{{ cv4pve_user }}" diff --git a/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 b/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 index d6eee5ab..2833d2e0 100644 --- a/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 +++ b/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 @@ -6,4 +6,4 @@ OnFailure=cv4pve_mail.service [Service] Type=simple -ExecStart=/usr/local/bin/cv4pve/cv4pve-autosnap --host=127.0.0.1 --api-token {{ cv4pve_api_user }}={{ cv4pve_api_token }} --vmid="{{ cv4pve_vmid }}" snap --label='daily' --keep="{{ cv4pve_keep_snapshots }}" --state +ExecStart=/usr/local/bin/cv4pve-{{ cv4pve_version }}/cv4pve-autosnap --host=127.0.0.1 --api-token {{ cv4pve_api_user }}={{ cv4pve_api_token }} --vmid="{{ cv4pve_vmid }}" snap --label='daily' --keep="{{ cv4pve_keep_snapshots }}" --state diff --git a/roles/mgrote_cv4pve_autosnap/templates/cv4pve.timer.j2 b/roles/mgrote_cv4pve_autosnap/templates/cv4pve.timer.j2 index ed002a77..81b1d5e3 100644 --- a/roles/mgrote_cv4pve_autosnap/templates/cv4pve.timer.j2 +++ b/roles/mgrote_cv4pve_autosnap/templates/cv4pve.timer.j2 @@ -6,6 +6,5 @@ Description=Timer: Trigger VM-Snapshots in PVE with cv4pve. OnCalendar=*-*-* {{ cv4pve_cron_hour }}:{{ cv4pve_cron_minute }}:00 RandomizedDelaySec=10 min - [Install] WantedBy=timers.target multi-user.target diff --git a/roles/mgrote_cv4pve_autosnap/templates/cv4pve_mail.service.j2 b/roles/mgrote_cv4pve_autosnap/templates/cv4pve_mail.service.j2 index 89a32874..691cc4e6 100644 --- a/roles/mgrote_cv4pve_autosnap/templates/cv4pve_mail.service.j2 +++ b/roles/mgrote_cv4pve_autosnap/templates/cv4pve_mail.service.j2 @@ -1,5 +1,4 @@ {{ file_header | default () }} - [Unit] Description=Send a Mail in case of an error in cv4pve.service. -- 2.43.0 From 226e3dcfcc4ad7e243ef9bfebd870f10c9e2497a Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 20:56:53 +0200 Subject: [PATCH 02/20] ff --- roles/mgrote_cv4pve_autosnap/tasks/main.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index 187deb59..93b3ac67 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -18,22 +18,12 @@ become: true ansible.builtin.unarchive: src: "{{ cv4pve_dl_link }}" - dest: /tmp/cv4pve/cv4pve-autosnap-linux-x64-{{ cv4pve_version }}.zip + dest: /tmp/cv4pve/cv4pve-autosnap-linux-x64-{{ cv4pve_version }} mode: '0775' owner: "{{ cv4pve_user }}" group: "{{ cv4pve_user_group }}" remote_src: yes -- name: extract archives - become: true - ansible.builtin.unarchive: - src: /tmp/cv4pve/cv4pve-autosnap-linux-x64-{{ cv4pve_version }}.zip - dest: /usr/local/bin/cv4pve-{{ cv4pve_version }} - remote_src: true - mode: a+x - owner: "{{ cv4pve_user }}" - group: "{{ cv4pve_user_group }}" - - name: template cv4pve.service become: true ansible.builtin.template: -- 2.43.0 From 6107294a226e9fe130475f22df839539e45c0ce0 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:09:21 +0200 Subject: [PATCH 03/20] ff --- roles/mgrote_cv4pve_autosnap/tasks/main.yml | 26 ++++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index 93b3ac67..012d49c0 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -3,7 +3,6 @@ ansible.builtin.include_tasks: user.yml - name: create directories - become: true ansible.builtin.file: path: "{{ item }}" state: directory @@ -11,21 +10,24 @@ group: "{{ cv4pve_user_group }}" mode: "0644" loop: - - '/tmp/cv4pve' - - '/usr/local/bin/cv4pve' + - '/usr/local/bin/cv4pve-{{ cv4pve_version }}/' - name: download archives - become: true ansible.builtin.unarchive: src: "{{ cv4pve_dl_link }}" - dest: /tmp/cv4pve/cv4pve-autosnap-linux-x64-{{ cv4pve_version }} + dest: /usr/local/bin/cv4pve/ mode: '0775' owner: "{{ cv4pve_user }}" group: "{{ cv4pve_user_group }}" remote_src: yes + creates: /usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} + list_files: true + +- name: move + ansible.builtin.command: | + mv /usr/local/bin/cv4pve/cv4pve-autosnap /usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} - name: template cv4pve.service - become: true ansible.builtin.template: src: cv4pve.service.j2 dest: /etc/systemd/system/cv4pve.service @@ -36,7 +38,6 @@ - systemctl daemon-reload - name: template cv4pve_mail.service - become: true ansible.builtin.template: src: cv4pve_mail.service.j2 dest: /etc/systemd/system/cv4pve_mail.service @@ -47,7 +48,6 @@ - systemctl daemon-reload - name: template cv4pve.timer - become: true ansible.builtin.template: src: cv4pve.timer.j2 dest: /etc/systemd/system/cv4pve.timer @@ -58,8 +58,16 @@ - systemctl daemon-reload - name: systemctl start cv4pve.timer - become: true ansible.builtin.systemd: name: cv4pve.timer state: started enabled: true + + +- name: remove old cv4pve versions + ansible.builtin.command: | + rm -rf /tmp/cv4pve/cv4pve-autosnap-linux-x64-{{ cv4pve_version }} + path: "{{ item['path'] }}" + state: absent + with_items: "{{ find_results['files'] }}" +... -- 2.43.0 From 54a5dc16d51b0ff6bdb7043279507732f7b35445 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:10:04 +0200 Subject: [PATCH 04/20] ff --- playbooks/3_service/pve.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/playbooks/3_service/pve.yml b/playbooks/3_service/pve.yml index 3e5b3a4d..1304eed7 100644 --- a/playbooks/3_service/pve.yml +++ b/playbooks/3_service/pve.yml @@ -16,7 +16,8 @@ - role: mgrote_smart tags: "smart" - role: mgrote_cv4pve_autosnap - tags: "cv4pve" + tags: cv4pve + become: true - role: mgrote_proxmox_bind_mounts tags: "bindmounts" - role: mgrote_proxmox_lxc_profiles -- 2.43.0 From dc3c0e8ffb46998e5ece5faf3c3c1edb3dd1ca25 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:11:16 +0200 Subject: [PATCH 05/20] ff --- roles/mgrote_cv4pve_autosnap/tasks/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index 012d49c0..d60a2f92 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -22,10 +22,12 @@ remote_src: yes creates: /usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} list_files: true + register: download - name: move ansible.builtin.command: | mv /usr/local/bin/cv4pve/cv4pve-autosnap /usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} + when: download.changed - name: template cv4pve.service ansible.builtin.template: -- 2.43.0 From 41a92ef163ff5d3926d89613b026f56ab10f7ad6 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:12:35 +0200 Subject: [PATCH 06/20] ff --- roles/mgrote_cv4pve_autosnap/tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index d60a2f92..38b27ca2 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -10,7 +10,8 @@ group: "{{ cv4pve_user_group }}" mode: "0644" loop: - - '/usr/local/bin/cv4pve-{{ cv4pve_version }}/' + - "/usr/local/bin/cv4pve-{{ cv4pve_version }}/" + - /usr/local/bin/cv4pve/ - name: download archives ansible.builtin.unarchive: @@ -71,5 +72,4 @@ rm -rf /tmp/cv4pve/cv4pve-autosnap-linux-x64-{{ cv4pve_version }} path: "{{ item['path'] }}" state: absent - with_items: "{{ find_results['files'] }}" ... -- 2.43.0 From 14dfe39fd03c4bd90d535698021f9ef772700855 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:14:26 +0200 Subject: [PATCH 07/20] ff --- group_vars/pve.yml | 2 +- roles/mgrote_cv4pve_autosnap/tasks/main.yml | 5 +---- roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/group_vars/pve.yml b/group_vars/pve.yml index 63d8ca55..d59531f1 100644 --- a/group_vars/pve.yml +++ b/group_vars/pve.yml @@ -29,7 +29,7 @@ users: allow_passwordless_sudo: true ### cv4pve -cv4pve_version: "v1.14.8" +cv4pve_version: "v1.14.7" ### mgrote_apt_manage_packages apt_packages_extra: diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index 38b27ca2..1247add7 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -4,14 +4,11 @@ - name: create directories ansible.builtin.file: - path: "{{ item }}" + path: "/usr/local/bin/cv4pve/" state: directory owner: "{{ cv4pve_user }}" group: "{{ cv4pve_user_group }}" mode: "0644" - loop: - - "/usr/local/bin/cv4pve-{{ cv4pve_version }}/" - - /usr/local/bin/cv4pve/ - name: download archives ansible.builtin.unarchive: diff --git a/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 b/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 index 2833d2e0..1a86fbe7 100644 --- a/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 +++ b/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 @@ -6,4 +6,4 @@ OnFailure=cv4pve_mail.service [Service] Type=simple -ExecStart=/usr/local/bin/cv4pve-{{ cv4pve_version }}/cv4pve-autosnap --host=127.0.0.1 --api-token {{ cv4pve_api_user }}={{ cv4pve_api_token }} --vmid="{{ cv4pve_vmid }}" snap --label='daily' --keep="{{ cv4pve_keep_snapshots }}" --state +ExecStart=/usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} --host=127.0.0.1 --api-token {{ cv4pve_api_user }}={{ cv4pve_api_token }} --vmid="{{ cv4pve_vmid }}" snap --label='daily' --keep="{{ cv4pve_keep_snapshots }}" --state -- 2.43.0 From fe036308592d86a1a516ef064351caa8375e198e Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:17:13 +0200 Subject: [PATCH 08/20] ff --- roles/mgrote_cv4pve_autosnap/tasks/main.yml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index 1247add7..386e9553 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -63,10 +63,23 @@ state: started enabled: true +- name: Capture files to delete + find: + paths: /usr/local/bin/cv4pve + file_type: file + excludes: + - "/usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }}" + register: found_files -- name: remove old cv4pve versions - ansible.builtin.command: | - rm -rf /tmp/cv4pve/cv4pve-autosnap-linux-x64-{{ cv4pve_version }} - path: "{{ item['path'] }}" +- name: Delete files + file: + path: "{{ item.path }}" state: absent + with_items: "{{ found_files['files'] }}" ... + + +# permissions +# etxte +#linter +# varioablen -- 2.43.0 From dd03d7580b6012a7a20f90b541a065b7d6ee8d85 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:18:56 +0200 Subject: [PATCH 09/20] ff --- roles/mgrote_cv4pve_autosnap/tasks/main.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index 386e9553..dff16a5d 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -64,15 +64,16 @@ enabled: true - name: Capture files to delete - find: + ansible.builtin.find: paths: /usr/local/bin/cv4pve file_type: file + use_regex: false excludes: - - "/usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }}" + - "cv4pve-autosnap-{{ cv4pve_version }}" register: found_files - name: Delete files - file: + ansible.builtin.file: path: "{{ item.path }}" state: absent with_items: "{{ found_files['files'] }}" -- 2.43.0 From 297db973f5a2487e0db175f3e8946f96e59e9e37 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:19:46 +0200 Subject: [PATCH 10/20] ff --- group_vars/pve.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/group_vars/pve.yml b/group_vars/pve.yml index d59531f1..63d8ca55 100644 --- a/group_vars/pve.yml +++ b/group_vars/pve.yml @@ -29,7 +29,7 @@ users: allow_passwordless_sudo: true ### cv4pve -cv4pve_version: "v1.14.7" +cv4pve_version: "v1.14.8" ### mgrote_apt_manage_packages apt_packages_extra: -- 2.43.0 From 1c159e4b47a5e07e1dc07b240be8d346af636556 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:21:38 +0200 Subject: [PATCH 11/20] ff --- .../mgrote_cv4pve_autosnap/tasks/install.yml | 41 ++++++++++ roles/mgrote_cv4pve_autosnap/tasks/main.yml | 78 +------------------ roles/mgrote_cv4pve_autosnap/tasks/systemd | 38 +++++++++ 3 files changed, 83 insertions(+), 74 deletions(-) create mode 100644 roles/mgrote_cv4pve_autosnap/tasks/install.yml create mode 100644 roles/mgrote_cv4pve_autosnap/tasks/systemd diff --git a/roles/mgrote_cv4pve_autosnap/tasks/install.yml b/roles/mgrote_cv4pve_autosnap/tasks/install.yml new file mode 100644 index 00000000..ace63a08 --- /dev/null +++ b/roles/mgrote_cv4pve_autosnap/tasks/install.yml @@ -0,0 +1,41 @@ +--- +- name: create directories + ansible.builtin.file: + path: "/usr/local/bin/cv4pve/" + state: directory + owner: "{{ cv4pve_user }}" + group: "{{ cv4pve_user_group }}" + mode: "0644" + +- name: download archives + ansible.builtin.unarchive: + src: "{{ cv4pve_dl_link }}" + dest: /usr/local/bin/cv4pve/ + mode: '0775' + owner: "{{ cv4pve_user }}" + group: "{{ cv4pve_user_group }}" + remote_src: yes + creates: /usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} + list_files: true + register: download + +- name: move + ansible.builtin.command: | + mv /usr/local/bin/cv4pve/cv4pve-autosnap /usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} + when: download.changed + +- name: Capture files to delete + ansible.builtin.find: + paths: /usr/local/bin/cv4pve + file_type: file + use_regex: false + excludes: + - "cv4pve-autosnap-{{ cv4pve_version }}" + register: found_files + +- name: Delete files + ansible.builtin.file: + path: "{{ item.path }}" + state: absent + with_items: "{{ found_files['files'] }}" +... diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index dff16a5d..03dc4eef 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -2,81 +2,11 @@ - name: include user tasks ansible.builtin.include_tasks: user.yml -- name: create directories - ansible.builtin.file: - path: "/usr/local/bin/cv4pve/" - state: directory - owner: "{{ cv4pve_user }}" - group: "{{ cv4pve_user_group }}" - mode: "0644" +- name: include install tasks + ansible.builtin.include_tasks: install.yml -- name: download archives - ansible.builtin.unarchive: - src: "{{ cv4pve_dl_link }}" - dest: /usr/local/bin/cv4pve/ - mode: '0775' - owner: "{{ cv4pve_user }}" - group: "{{ cv4pve_user_group }}" - remote_src: yes - creates: /usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} - list_files: true - register: download - -- name: move - ansible.builtin.command: | - mv /usr/local/bin/cv4pve/cv4pve-autosnap /usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} - when: download.changed - -- name: template cv4pve.service - ansible.builtin.template: - src: cv4pve.service.j2 - dest: /etc/systemd/system/cv4pve.service - owner: root - group: root - mode: "0644" - notify: - - systemctl daemon-reload - -- name: template cv4pve_mail.service - ansible.builtin.template: - src: cv4pve_mail.service.j2 - dest: /etc/systemd/system/cv4pve_mail.service - owner: root - group: root - mode: "0644" - notify: - - systemctl daemon-reload - -- name: template cv4pve.timer - ansible.builtin.template: - src: cv4pve.timer.j2 - dest: /etc/systemd/system/cv4pve.timer - owner: root - group: root - mode: "0644" - notify: - - systemctl daemon-reload - -- name: systemctl start cv4pve.timer - ansible.builtin.systemd: - name: cv4pve.timer - state: started - enabled: true - -- name: Capture files to delete - ansible.builtin.find: - paths: /usr/local/bin/cv4pve - file_type: file - use_regex: false - excludes: - - "cv4pve-autosnap-{{ cv4pve_version }}" - register: found_files - -- name: Delete files - ansible.builtin.file: - path: "{{ item.path }}" - state: absent - with_items: "{{ found_files['files'] }}" +- name: include systemd tasks + ansible.builtin.include_tasks: systemd.yml ... diff --git a/roles/mgrote_cv4pve_autosnap/tasks/systemd b/roles/mgrote_cv4pve_autosnap/tasks/systemd new file mode 100644 index 00000000..c72bd865 --- /dev/null +++ b/roles/mgrote_cv4pve_autosnap/tasks/systemd @@ -0,0 +1,38 @@ +--- +- name: template cv4pve.service + ansible.builtin.template: + src: cv4pve.service.j2 + dest: /etc/systemd/system/cv4pve.service + owner: root + group: root + mode: "0644" + no_log: true + notify: + - systemctl daemon-reload + +- name: template cv4pve_mail.service + ansible.builtin.template: + src: cv4pve_mail.service.j2 + dest: /etc/systemd/system/cv4pve_mail.service + owner: root + group: root + mode: "0644" + notify: + - systemctl daemon-reload + +- name: template cv4pve.timer + ansible.builtin.template: + src: cv4pve.timer.j2 + dest: /etc/systemd/system/cv4pve.timer + owner: root + group: root + mode: "0644" + notify: + - systemctl daemon-reload + +- name: systemctl start cv4pve.timer + ansible.builtin.systemd: + name: cv4pve.timer + state: started + enabled: true +... -- 2.43.0 From 71df05139ec2a7b4cce7d0a9ed5c4e8285be2d0e Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:21:57 +0200 Subject: [PATCH 12/20] d --- roles/mgrote_cv4pve_autosnap/tasks/{systemd => systemd.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename roles/mgrote_cv4pve_autosnap/tasks/{systemd => systemd.yml} (100%) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/systemd b/roles/mgrote_cv4pve_autosnap/tasks/systemd.yml similarity index 100% rename from roles/mgrote_cv4pve_autosnap/tasks/systemd rename to roles/mgrote_cv4pve_autosnap/tasks/systemd.yml -- 2.43.0 From b3884332ba151fe0e3aac2cf074b47647d16d31d Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:24:59 +0200 Subject: [PATCH 13/20] f --- roles/mgrote_cv4pve_autosnap/tasks/install.yml | 11 ++++++----- roles/mgrote_cv4pve_autosnap/tasks/systemd.yml | 8 ++++---- roles/mgrote_cv4pve_autosnap/tasks/user.yml | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/install.yml b/roles/mgrote_cv4pve_autosnap/tasks/install.yml index ace63a08..2c90d979 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/install.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/install.yml @@ -1,5 +1,5 @@ --- -- name: create directories +- name: Ensure needed directories exist ansible.builtin.file: path: "/usr/local/bin/cv4pve/" state: directory @@ -7,7 +7,7 @@ group: "{{ cv4pve_user_group }}" mode: "0644" -- name: download archives +- name: Download specified version ansible.builtin.unarchive: src: "{{ cv4pve_dl_link }}" dest: /usr/local/bin/cv4pve/ @@ -19,12 +19,13 @@ list_files: true register: download -- name: move +- name: Rename binary ansible.builtin.command: | mv /usr/local/bin/cv4pve/cv4pve-autosnap /usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} when: download.changed -- name: Capture files to delete +# https://stackoverflow.com/questions/20252057/using-ansible-how-would-i-delete-all-items-except-for-a-specified-set-in-a-dire +- name: Find old versions ansible.builtin.find: paths: /usr/local/bin/cv4pve file_type: file @@ -33,7 +34,7 @@ - "cv4pve-autosnap-{{ cv4pve_version }}" register: found_files -- name: Delete files +- name: Ensure old versions are absent ansible.builtin.file: path: "{{ item.path }}" state: absent diff --git a/roles/mgrote_cv4pve_autosnap/tasks/systemd.yml b/roles/mgrote_cv4pve_autosnap/tasks/systemd.yml index c72bd865..d089d485 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/systemd.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/systemd.yml @@ -1,5 +1,5 @@ --- -- name: template cv4pve.service +- name: Ensure service-unit (cv4pve) is templated ansible.builtin.template: src: cv4pve.service.j2 dest: /etc/systemd/system/cv4pve.service @@ -10,7 +10,7 @@ notify: - systemctl daemon-reload -- name: template cv4pve_mail.service +- name: Ensure service-unit (mail) is templated ansible.builtin.template: src: cv4pve_mail.service.j2 dest: /etc/systemd/system/cv4pve_mail.service @@ -20,7 +20,7 @@ notify: - systemctl daemon-reload -- name: template cv4pve.timer +- name: Ensure service-unit (timer) is templated ansible.builtin.template: src: cv4pve.timer.j2 dest: /etc/systemd/system/cv4pve.timer @@ -30,7 +30,7 @@ notify: - systemctl daemon-reload -- name: systemctl start cv4pve.timer +- name: Ensure timer is started is templated ansible.builtin.systemd: name: cv4pve.timer state: started diff --git a/roles/mgrote_cv4pve_autosnap/tasks/user.yml b/roles/mgrote_cv4pve_autosnap/tasks/user.yml index f304dc92..7ceab35b 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/user.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/user.yml @@ -1,5 +1,5 @@ --- -- name: ensure group exists +- name: Ensure group exists become: true ansible.builtin.group: name: "{{ cv4pve_user_group }}" @@ -7,7 +7,7 @@ when: - cv4pve_user_group is defined -- name: ensure user exists +- name: Ensure user exists become: true ansible.builtin.user: name: "{{ cv4pve_user }}" -- 2.43.0 From 670db818b8648c6b143803eedddabcb8cc822c30 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:26:28 +0200 Subject: [PATCH 14/20] d --- roles/mgrote_cv4pve_autosnap/tasks/install.yml | 2 +- roles/mgrote_cv4pve_autosnap/tasks/main.yml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/install.yml b/roles/mgrote_cv4pve_autosnap/tasks/install.yml index 2c90d979..08943f31 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/install.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/install.yml @@ -11,7 +11,7 @@ ansible.builtin.unarchive: src: "{{ cv4pve_dl_link }}" dest: /usr/local/bin/cv4pve/ - mode: '0775' + mode: '0755' owner: "{{ cv4pve_user }}" group: "{{ cv4pve_user_group }}" remote_src: yes diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index 03dc4eef..c584cf20 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -11,6 +11,5 @@ # permissions -# etxte #linter # varioablen -- 2.43.0 From f5611498042e7073eb422f3c3304b5934a811371 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:28:18 +0200 Subject: [PATCH 15/20] f --- roles/mgrote_cv4pve_autosnap/tasks/install.yml | 10 +++++----- .../mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/install.yml b/roles/mgrote_cv4pve_autosnap/tasks/install.yml index 08943f31..9ebea2ab 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/install.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/install.yml @@ -1,7 +1,7 @@ --- - name: Ensure needed directories exist ansible.builtin.file: - path: "/usr/local/bin/cv4pve/" + path: "{{ cv4pve_base_path }}" state: directory owner: "{{ cv4pve_user }}" group: "{{ cv4pve_user_group }}" @@ -10,24 +10,24 @@ - name: Download specified version ansible.builtin.unarchive: src: "{{ cv4pve_dl_link }}" - dest: /usr/local/bin/cv4pve/ + dest: "{{ cv4pve_base_path }}" mode: '0755' owner: "{{ cv4pve_user }}" group: "{{ cv4pve_user_group }}" remote_src: yes - creates: /usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} + creates: "{{ cv4pve_base_path }}/cv4pve-autosnap-{{ cv4pve_version }}" list_files: true register: download - name: Rename binary ansible.builtin.command: | - mv /usr/local/bin/cv4pve/cv4pve-autosnap /usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} + mv "{{ cv4pve_base_path }}/cv4pve-autosnap" "{{ cv4pve_base_path }}/cv4pve-autosnap-{{ cv4pve_version }}" when: download.changed # https://stackoverflow.com/questions/20252057/using-ansible-how-would-i-delete-all-items-except-for-a-specified-set-in-a-dire - name: Find old versions ansible.builtin.find: - paths: /usr/local/bin/cv4pve + paths: "{{ cv4pve_base_path }}" file_type: file use_regex: false excludes: diff --git a/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 b/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 index 1a86fbe7..11490cf1 100644 --- a/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 +++ b/roles/mgrote_cv4pve_autosnap/templates/cv4pve.service.j2 @@ -6,4 +6,4 @@ OnFailure=cv4pve_mail.service [Service] Type=simple -ExecStart=/usr/local/bin/cv4pve/cv4pve-autosnap-{{ cv4pve_version }} --host=127.0.0.1 --api-token {{ cv4pve_api_user }}={{ cv4pve_api_token }} --vmid="{{ cv4pve_vmid }}" snap --label='daily' --keep="{{ cv4pve_keep_snapshots }}" --state +ExecStart={{ cv4pve_base_path }}/cv4pve-autosnap-{{ cv4pve_version }} --host=127.0.0.1 --api-token {{ cv4pve_api_user }}={{ cv4pve_api_token }} --vmid="{{ cv4pve_vmid }}" snap --label='daily' --keep="{{ cv4pve_keep_snapshots }}" --state -- 2.43.0 From 3e568d9491b8b9574588433dfe32a18e43e6901c Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:28:42 +0200 Subject: [PATCH 16/20] ff --- roles/mgrote_cv4pve_autosnap/defaults/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/roles/mgrote_cv4pve_autosnap/defaults/main.yml b/roles/mgrote_cv4pve_autosnap/defaults/main.yml index 2a897263..94d480ef 100644 --- a/roles/mgrote_cv4pve_autosnap/defaults/main.yml +++ b/roles/mgrote_cv4pve_autosnap/defaults/main.yml @@ -15,3 +15,6 @@ cv4pve_user: cv4pve # url cv4pve_dl_link: https://github.com/Corsinvest/cv4pve-autosnap/releases/download/{{ cv4pve_version }}/cv4pve-autosnap-linux-x64.zip cv4pve_version: "v1.14.8" + + +cv4pve_base_path: /usr/local/bin/cv4pve -- 2.43.0 From 2aa163babf7f94169cd66cfb93e68ef1e1abc10a Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:31:08 +0200 Subject: [PATCH 17/20] ff --- group_vars/pve.yml | 7 ++++++- host_vars/pve5-test.mgrote.net.yml | 7 ------- host_vars/pve5.mgrote.net.yml | 7 ------- roles/mgrote_cv4pve_autosnap/defaults/main.yml | 2 +- roles/mgrote_cv4pve_autosnap/tasks/main.yml | 2 -- roles/mgrote_cv4pve_autosnap/tasks/user.yml | 1 + 6 files changed, 8 insertions(+), 18 deletions(-) diff --git a/group_vars/pve.yml b/group_vars/pve.yml index 63d8ca55..fbf1917f 100644 --- a/group_vars/pve.yml +++ b/group_vars/pve.yml @@ -28,7 +28,12 @@ users: allow_sudo: true allow_passwordless_sudo: true -### cv4pve + +### mgrote_cv4pve_autosnap +cv4pve_api_user: root@pam!cv4pve-autosnap +cv4pve_api_token: "{{ lookup('keepass', 'cv4pve_api_token', 'password') }}" +cv4pve_vmid: all,-115 +cv4pve_keep_snapshots: 5 cv4pve_version: "v1.14.8" ### mgrote_apt_manage_packages diff --git a/host_vars/pve5-test.mgrote.net.yml b/host_vars/pve5-test.mgrote.net.yml index fa97a4c2..41f8eeec 100644 --- a/host_vars/pve5-test.mgrote.net.yml +++ b/host_vars/pve5-test.mgrote.net.yml @@ -153,13 +153,6 @@ sanoid_datasets: snapshots: true template: '3tage' -### mgrote_cv4pve-autosnap -cv4pve_api_user: root@pam!cv4pve-autosnap -cv4pve_api_token: "{{ lookup('keepass', 'cv4pve_api_token', 'password') }}" -cv4pve_vmid: all -cv4pve_keep_snapshots: 5 -cv4pve_dl_link: "https://github.com/Corsinvest/cv4pve-autosnap/releases/download/v1.10.0/cv4pve-autosnap-linux-x64.zip" - ### mgrote_proxmox_bind_mounts pve_bind_mounts: - vmid: 100 diff --git a/host_vars/pve5.mgrote.net.yml b/host_vars/pve5.mgrote.net.yml index 6c0618bc..c51eacec 100644 --- a/host_vars/pve5.mgrote.net.yml +++ b/host_vars/pve5.mgrote.net.yml @@ -170,13 +170,6 @@ sanoid_datasets: snapshots: true template: 'pve3tage' -### mgrote_cv4pve-autosnap -cv4pve_api_user: root@pam!cv4pve-autosnap -cv4pve_api_token: "{{ lookup('keepass', 'cv4pve_api_token', 'password') }}" -cv4pve_vmid: all,-115 -cv4pve_keep_snapshots: 5 -cv4pve_dl_link: "https://github.com/Corsinvest/cv4pve-autosnap/releases/download/v1.14.7/cv4pve-autosnap-linux-x64.zip" - ### mgrote_proxmox_bind_mounts pve_bind_mounts: ### fileserver3 diff --git a/roles/mgrote_cv4pve_autosnap/defaults/main.yml b/roles/mgrote_cv4pve_autosnap/defaults/main.yml index 94d480ef..ce07c5d1 100644 --- a/roles/mgrote_cv4pve_autosnap/defaults/main.yml +++ b/roles/mgrote_cv4pve_autosnap/defaults/main.yml @@ -3,7 +3,7 @@ cv4pve_cron_minute: "39" cv4pve_cron_hour: "5" # proxmox api-token and user -cv4pve_api_token: "XXXXXXXXXXXXXXXXXXXXXX" +cv4pve_api_token: "supersecret" cv4pve_api_user: "root@pam!test2" # which vm to snapshot cv4pve_vmid: all diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index c584cf20..047aae01 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -10,6 +10,4 @@ ... -# permissions #linter -# varioablen diff --git a/roles/mgrote_cv4pve_autosnap/tasks/user.yml b/roles/mgrote_cv4pve_autosnap/tasks/user.yml index 7ceab35b..505dfbbd 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/user.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/user.yml @@ -17,3 +17,4 @@ when: - cv4pve_user_group is defined - cv4pve_user is defined +... -- 2.43.0 From c636811333cd418a4cb32466b16a999586846a96 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:31:21 +0200 Subject: [PATCH 18/20] dd --- roles/mgrote_cv4pve_autosnap/defaults/main.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/roles/mgrote_cv4pve_autosnap/defaults/main.yml b/roles/mgrote_cv4pve_autosnap/defaults/main.yml index ce07c5d1..fe29f131 100644 --- a/roles/mgrote_cv4pve_autosnap/defaults/main.yml +++ b/roles/mgrote_cv4pve_autosnap/defaults/main.yml @@ -15,6 +15,4 @@ cv4pve_user: cv4pve # url cv4pve_dl_link: https://github.com/Corsinvest/cv4pve-autosnap/releases/download/{{ cv4pve_version }}/cv4pve-autosnap-linux-x64.zip cv4pve_version: "v1.14.8" - - cv4pve_base_path: /usr/local/bin/cv4pve -- 2.43.0 From f39915788896f3be782b5edcb8907c8d8ae6b2e7 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:38:09 +0200 Subject: [PATCH 19/20] dd --- roles/mgrote_cv4pve_autosnap/tasks/install.yml | 4 ++-- roles/mgrote_cv4pve_autosnap/tasks/main.yml | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/install.yml b/roles/mgrote_cv4pve_autosnap/tasks/install.yml index 9ebea2ab..ee542ceb 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/install.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/install.yml @@ -14,12 +14,12 @@ mode: '0755' owner: "{{ cv4pve_user }}" group: "{{ cv4pve_user_group }}" - remote_src: yes + remote_src: true creates: "{{ cv4pve_base_path }}/cv4pve-autosnap-{{ cv4pve_version }}" list_files: true register: download -- name: Rename binary +- name: Rename binary # noq no-changed-when no-handler ansible.builtin.command: | mv "{{ cv4pve_base_path }}/cv4pve-autosnap" "{{ cv4pve_base_path }}/cv4pve-autosnap-{{ cv4pve_version }}" when: download.changed diff --git a/roles/mgrote_cv4pve_autosnap/tasks/main.yml b/roles/mgrote_cv4pve_autosnap/tasks/main.yml index 047aae01..e9d2f9dc 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/main.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/main.yml @@ -8,6 +8,3 @@ - name: include systemd tasks ansible.builtin.include_tasks: systemd.yml ... - - -#linter -- 2.43.0 From c520144ef4a92882c4dd8594069c146792d4e490 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:39:06 +0200 Subject: [PATCH 20/20] d --- roles/mgrote_cv4pve_autosnap/tasks/install.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/mgrote_cv4pve_autosnap/tasks/install.yml b/roles/mgrote_cv4pve_autosnap/tasks/install.yml index ee542ceb..f2497907 100644 --- a/roles/mgrote_cv4pve_autosnap/tasks/install.yml +++ b/roles/mgrote_cv4pve_autosnap/tasks/install.yml @@ -19,7 +19,7 @@ list_files: true register: download -- name: Rename binary # noq no-changed-when no-handler +- name: Rename binary # noqa no-changed-when no-handler ansible.builtin.command: | mv "{{ cv4pve_base_path }}/cv4pve-autosnap" "{{ cv4pve_base_path }}/cv4pve-autosnap-{{ cv4pve_version }}" when: download.changed -- 2.43.0