From 1c159e4b47a5e07e1dc07b240be8d346af636556 Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Sun, 14 Apr 2024 21:21:38 +0200 Subject: [PATCH] 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 +...