From a251871fd0428b9daf82bd75c6c091de706ee7ab Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Thu, 4 Jan 2024 13:27:07 +0100 Subject: [PATCH] refactored to timer routine --- .../backup-docker-to-local/handlers/main.yml | 14 +--------- roles/backup-docker-to-local/tasks/main.yml | 15 +++++++---- .../templates/backup-docker-to-local.timer.j2 | 10 ------- roles/backup-remote-to-local/tasks/main.yml | 16 +++++++----- .../templates/backup-remote-to-local.timer.j2 | 10 ------- roles/cleanup-backups-timer/handlers/main.yml | 12 --------- roles/cleanup-backups-timer/tasks/main.yml | 17 +++++++----- .../templates/cleanup-backups.timer.j2 | 10 ------- roles/cleanup-disc-space/handlers/main.yml | 6 ----- roles/cleanup-disc-space/tasks/main.yml | 16 +++++++----- .../templates/cleanup-disc-space.timer.j2 | 10 ------- .../handlers/main.yml | 7 ----- .../tasks/main.yml | 17 +++++++----- .../cleanup-failed-docker-backups.timer.j2 | 10 ------- roles/docker-mailu/handlers/main.yml | 8 +----- roles/docker-mailu/tasks/main.yml | 14 +++++----- .../deploy-letsencrypt-mailu.timer.j2 | 10 ------- roles/heal-docker/handlers/main.yml | 6 ----- roles/heal-docker/tasks/main.yml | 17 +++++++----- .../templates/heal-docker.timer.j2 | 10 ------- roles/health-btrfs/handlers/main.yml | 8 +----- roles/health-btrfs/tasks/main.yml | 16 +++++++----- .../templates/health-btrfs.timer.j2 | 10 ------- roles/health-disc-space/handlers/main.yml | 6 ----- roles/health-disc-space/tasks/main.yml | 16 +++++++----- .../templates/health-disc-space.timer.j2 | 10 ------- .../health-docker-container/handlers/main.yml | 6 ----- roles/health-docker-container/tasks/main.yml | 17 +++++++----- .../health-docker-container.timer.j2 | 10 ------- roles/health-docker-volumes/handlers/main.yml | 6 ----- roles/health-docker-volumes/tasks/main.yml | 17 +++++++----- .../templates/health-docker-volumes.timer.j2 | 10 ------- roles/health-journalctl/handlers/main.yml | 6 ----- roles/health-journalctl/tasks/main.yml | 26 ++++++++++++++----- .../templates/health-journalctl.timer.j2 | 10 ------- roles/health-nginx/handlers/main.yml | 7 ----- roles/health-nginx/tasks/main.yml | 17 +++++++----- .../templates/health-nginx.timer.j2 | 10 ------- roles/nginx-certbot/handlers/main.yml | 8 +----- roles/nginx-certbot/tasks/main.yml | 24 ++++++++++------- .../nginx-certbot/templates/certbot.timer.j2 | 10 ------- ...ot.service.j2 => nginx-certbot.service.j2} | 0 roles/systemd-timer/templates/dummy.timer.j2 | 2 +- 43 files changed, 152 insertions(+), 335 deletions(-) delete mode 100644 roles/backup-docker-to-local/templates/backup-docker-to-local.timer.j2 delete mode 100644 roles/backup-remote-to-local/templates/backup-remote-to-local.timer.j2 delete mode 100644 roles/cleanup-backups-timer/handlers/main.yml delete mode 100644 roles/cleanup-backups-timer/templates/cleanup-backups.timer.j2 delete mode 100644 roles/cleanup-disc-space/templates/cleanup-disc-space.timer.j2 delete mode 100644 roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.timer.j2 delete mode 100644 roles/docker-mailu/templates/deploy-letsencrypt-mailu.timer.j2 delete mode 100644 roles/heal-docker/templates/heal-docker.timer.j2 delete mode 100644 roles/health-btrfs/templates/health-btrfs.timer.j2 delete mode 100644 roles/health-disc-space/templates/health-disc-space.timer.j2 delete mode 100644 roles/health-docker-container/templates/health-docker-container.timer.j2 delete mode 100644 roles/health-docker-volumes/templates/health-docker-volumes.timer.j2 delete mode 100644 roles/health-journalctl/templates/health-journalctl.timer.j2 delete mode 100644 roles/health-nginx/templates/health-nginx.timer.j2 delete mode 100644 roles/nginx-certbot/templates/certbot.timer.j2 rename roles/nginx-certbot/templates/{certbot.service.j2 => nginx-certbot.service.j2} (100%) diff --git a/roles/backup-docker-to-local/handlers/main.yml b/roles/backup-docker-to-local/handlers/main.yml index 687aacda..f44f6d7c 100644 --- a/roles/backup-docker-to-local/handlers/main.yml +++ b/roles/backup-docker-to-local/handlers/main.yml @@ -1,16 +1,4 @@ - name: "reload backup-docker-to-local.service" systemd: name: backup-docker-to-local.service - daemon_reload: yes - -- name: "reload backup-docker-to-local-everything.service" - systemd: - name: backup-docker-to-local-everything.service - daemon_reload: yes - -- name: "restart backup-docker-to-local.timer" - systemd: - name: backup-docker-to-local.timer - state: started - enabled: yes - daemon_reload: yes + daemon_reload: yes \ No newline at end of file diff --git a/roles/backup-docker-to-local/tasks/main.yml b/roles/backup-docker-to-local/tasks/main.yml index eb0632b7..3ac8acc0 100644 --- a/roles/backup-docker-to-local/tasks/main.yml +++ b/roles/backup-docker-to-local/tasks/main.yml @@ -34,11 +34,16 @@ notify: reload backup-docker-to-local.service when: run_once_backup_docker_to_local is not defined -- name: configure backup-docker-to-local.timer.tpl - template: src=backup-docker-to-local.timer.j2 dest=/etc/systemd/system/backup-docker-to-local.timer - register: backup_docker_to_local_timer - changed_when: backup_docker_to_local_timer.changed or activate_all_timers | bool - notify: restart backup-docker-to-local.timer +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + when: run_once_backup_docker_to_local is not defined + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_backup_docker_to_local}}" when: run_once_backup_docker_to_local is not defined - name: seed database values diff --git a/roles/backup-docker-to-local/templates/backup-docker-to-local.timer.j2 b/roles/backup-docker-to-local/templates/backup-docker-to-local.timer.j2 deleted file mode 100644 index c7e4d75c..00000000 --- a/roles/backup-docker-to-local/templates/backup-docker-to-local.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=backups the docker volumes - -[Timer] -OnCalendar={{on_calendar_backup_docker_to_local}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=false - -[Install] -WantedBy=timers.target diff --git a/roles/backup-remote-to-local/tasks/main.yml b/roles/backup-remote-to-local/tasks/main.yml index 57c70220..0aafc60b 100644 --- a/roles/backup-remote-to-local/tasks/main.yml +++ b/roles/backup-remote-to-local/tasks/main.yml @@ -14,15 +14,19 @@ template: src=backup-remote-to-local.service.j2 dest=/etc/systemd/system/backup-remote-to-local.service notify: reload backup-remote-to-local service -- name: create backup-remote-to-local.timer - template: src=backup-remote-to-local.timer.j2 dest=/etc/systemd/system/backup-remote-to-local.timer - register: backup_backup_remote_to_local_timer - changed_when: backup_backup_remote_to_local_timer.changed or activate_all_timers | bool - notify: restart backup-remote-to-local timer - - name: create backups-remote-to-local.sh template: src: backups-remote-to-local.sh.j2 dest: "{{docker_backup_remote_to_local_folder}}backups-remote-to-local.sh" mode: 0755 +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_backup_remote_to_local}}" + diff --git a/roles/backup-remote-to-local/templates/backup-remote-to-local.timer.j2 b/roles/backup-remote-to-local/templates/backup-remote-to-local.timer.j2 deleted file mode 100644 index 666c21ff..00000000 --- a/roles/backup-remote-to-local/templates/backup-remote-to-local.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=starts pull remote backup timer - -[Timer] -OnCalendar={{on_calendar_backup_remote_to_local}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=false - -[Install] -WantedBy=timers.target diff --git a/roles/cleanup-backups-timer/handlers/main.yml b/roles/cleanup-backups-timer/handlers/main.yml deleted file mode 100644 index 0f0c8dcb..00000000 --- a/roles/cleanup-backups-timer/handlers/main.yml +++ /dev/null @@ -1,12 +0,0 @@ -- name: "restart cleanup-backups.timer" - systemd: - name: cleanup-backups.timer - state: restarted - enabled: yes - daemon_reload: yes - when: run_once_cleanup_backup_timer is not defined - -- name: run the cleanup_backup_timer tasks once - set_fact: - run_once_cleanup_backup_timer: true - when: run_once_cleanup_backup_timer is not defined \ No newline at end of file diff --git a/roles/cleanup-backups-timer/tasks/main.yml b/roles/cleanup-backups-timer/tasks/main.yml index f15a4fc1..489b4a46 100644 --- a/roles/cleanup-backups-timer/tasks/main.yml +++ b/roles/cleanup-backups-timer/tasks/main.yml @@ -1,10 +1,13 @@ -- name: create cleanup-backups.timer - template: - src: "cleanup-backups.timer.j2" - dest: "/etc/systemd/system/cleanup-backups.timer" - register: cleanup_backups_timer - changed_when: cleanup_backups_timer.changed or activate_all_timers | bool - notify: restart cleanup-backups.timer +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + when: run_once_cleanup_backups_timer is not defined + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_cleanup_backups}}" when: run_once_cleanup_backups_timer is not defined - name: run the cleanup_backups_timer tasks once diff --git a/roles/cleanup-backups-timer/templates/cleanup-backups.timer.j2 b/roles/cleanup-backups-timer/templates/cleanup-backups.timer.j2 deleted file mode 100644 index 7a68add0..00000000 --- a/roles/cleanup-backups-timer/templates/cleanup-backups.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=starts cleanup-backups.service - -[Timer] -OnCalendar={{on_calendar_cleanup_backups}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=true - -[Install] -WantedBy=timers.target diff --git a/roles/cleanup-disc-space/handlers/main.yml b/roles/cleanup-disc-space/handlers/main.yml index 0797d3a5..3f342c5e 100644 --- a/roles/cleanup-disc-space/handlers/main.yml +++ b/roles/cleanup-disc-space/handlers/main.yml @@ -3,9 +3,3 @@ name: cleanup-disc-space.service enabled: yes daemon_reload: yes -- name: "restart cleanup-disc-space.timer" - systemd: - name: cleanup-disc-space.timer - state: restarted - enabled: yes - daemon_reload: yes diff --git a/roles/cleanup-disc-space/tasks/main.yml b/roles/cleanup-disc-space/tasks/main.yml index 26a66e51..ef0d90df 100644 --- a/roles/cleanup-disc-space/tasks/main.yml +++ b/roles/cleanup-disc-space/tasks/main.yml @@ -15,10 +15,12 @@ dest: /etc/systemd/system/cleanup-disc-space.service notify: reload cleanup-disc-space.service -- name: create cleanup-disc-space.timer - template: - src: cleanup-disc-space.timer.j2 - dest: /etc/systemd/system/cleanup-disc-space.timer - register: cleanup_disc_space_timer - changed_when: cleanup_disc_space_timer.changed or activate_all_timers | bool - notify: restart cleanup-disc-space.timer \ No newline at end of file +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_cleanup_disc_space}}" \ No newline at end of file diff --git a/roles/cleanup-disc-space/templates/cleanup-disc-space.timer.j2 b/roles/cleanup-disc-space/templates/cleanup-disc-space.timer.j2 deleted file mode 100644 index e367e3a7..00000000 --- a/roles/cleanup-disc-space/templates/cleanup-disc-space.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=starts cleanup-disc-space.service - -[Timer] -OnCalendar={{on_calendar_cleanup_disc_space}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=true - -[Install] -WantedBy=timers.target diff --git a/roles/cleanup-failed-docker-backups/handlers/main.yml b/roles/cleanup-failed-docker-backups/handlers/main.yml index cce18798..d96a6ae6 100644 --- a/roles/cleanup-failed-docker-backups/handlers/main.yml +++ b/roles/cleanup-failed-docker-backups/handlers/main.yml @@ -2,11 +2,4 @@ systemd: name: cleanup-failed-docker-backups.service enabled: yes - daemon_reload: yes - -- name: "restart cleanup-failed-docker-backups.timer" - systemd: - name: cleanup-failed-docker-backups.timer - state: restarted - enabled: yes daemon_reload: yes \ No newline at end of file diff --git a/roles/cleanup-failed-docker-backups/tasks/main.yml b/roles/cleanup-failed-docker-backups/tasks/main.yml index b36c0f18..5bf297cb 100644 --- a/roles/cleanup-failed-docker-backups/tasks/main.yml +++ b/roles/cleanup-failed-docker-backups/tasks/main.yml @@ -19,13 +19,16 @@ notify: reload cleanup-failed-docker-backups.service daemon when: run_once_cleanup_failed_docker_backups is not defined -- name: create cleanup-failed-docker-backups.timer - template: - src: cleanup-failed-docker-backups.timer.j2 - dest: /etc/systemd/system/cleanup-failed-docker-backups.timer - register: cleanup_failed_docker_backups_timer - changed_when: cleanup_failed_docker_backups_timer.changed or activate_all_timers | bool - notify: restart cleanup-failed-docker-backups.timer +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + when: run_once_cleanup_failed_docker_backups is not defined + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_cleanup_failed_docker}}" when: run_once_cleanup_failed_docker_backups is not defined - name: run the cleanup_failed_docker_backups tasks once diff --git a/roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.timer.j2 b/roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.timer.j2 deleted file mode 100644 index bcebf268..00000000 --- a/roles/cleanup-failed-docker-backups/templates/cleanup-failed-docker-backups.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=starts cleanup-failed-docker-backups.service - -[Timer] -OnCalendar={{on_calendar_cleanup_failed_docker}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=true - -[Install] -WantedBy=timers.target diff --git a/roles/docker-mailu/handlers/main.yml b/roles/docker-mailu/handlers/main.yml index c6dead42..1d8aec4a 100644 --- a/roles/docker-mailu/handlers/main.yml +++ b/roles/docker-mailu/handlers/main.yml @@ -4,10 +4,4 @@ name: deploy-letsencrypt-mailu.service state: restarted enabled: yes - daemon_reload: yes -- name: "restart deploy-letsencrypt-mailu.timer" - systemd: - name: deploy-letsencrypt-mailu.timer - state: restarted - enabled: yes - daemon_reload: yes + daemon_reload: yes \ No newline at end of file diff --git a/roles/docker-mailu/tasks/main.yml b/roles/docker-mailu/tasks/main.yml index 27a2632a..8bb1a1dc 100644 --- a/roles/docker-mailu/tasks/main.yml +++ b/roles/docker-mailu/tasks/main.yml @@ -54,10 +54,10 @@ dest: "/etc/systemd/system/deploy-letsencrypt-mailu.service" notify: restart deploy-letsencrypt-mailu.service -- name: configure deploy-letsencrypt-mailu.timer - template: - src: "deploy-letsencrypt-mailu.timer.j2" - dest: "/etc/systemd/system/deploy-letsencrypt-mailu.timer" - register: deploy_letsencrypt_mailu_timer - changed_when: deploy_letsencrypt_mailu_timer.changed or activate_all_timers | bool - notify: restart deploy-letsencrypt-mailu.timer \ No newline at end of file +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_deploy_mailu_certificates}}" + service_name: "deploy-letsencrypt-mailu" + persistent: "true" \ No newline at end of file diff --git a/roles/docker-mailu/templates/deploy-letsencrypt-mailu.timer.j2 b/roles/docker-mailu/templates/deploy-letsencrypt-mailu.timer.j2 deleted file mode 100644 index 79853124..00000000 --- a/roles/docker-mailu/templates/deploy-letsencrypt-mailu.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Deployment of Let's Encrypt's certificates - -[Timer] -OnCalendar={{on_calendar_deploy_mailu_certificates}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=true - -[Install] -WantedBy=timers.target diff --git a/roles/heal-docker/handlers/main.yml b/roles/heal-docker/handlers/main.yml index 5de34822..023255c6 100644 --- a/roles/heal-docker/handlers/main.yml +++ b/roles/heal-docker/handlers/main.yml @@ -2,9 +2,3 @@ systemd: name: heal-docker.service daemon_reload: yes -- name: "restart heal-docker.timer" - systemd: - name: heal-docker.timer - state: restarted - enabled: yes - daemon_reload: yes diff --git a/roles/heal-docker/tasks/main.yml b/roles/heal-docker/tasks/main.yml index 8c4c2c44..48dad7ef 100644 --- a/roles/heal-docker/tasks/main.yml +++ b/roles/heal-docker/tasks/main.yml @@ -18,13 +18,16 @@ notify: reload heal-docker.service when: run_once_heal_docker is not defined -- name: create heal-docker.timer - template: - src: heal-docker.timer.j2 - dest: "/etc/systemd/system/heal-docker.timer" - register: heal_docker_timer - changed_when: heal_docker_timer.changed or activate_all_timers | bool - notify: restart heal-docker.timer +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + when: run_once_heal_docker is not defined + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_heal_docker}}" when: run_once_heal_docker is not defined - name: run the heal_docker tasks once diff --git a/roles/heal-docker/templates/heal-docker.timer.j2 b/roles/heal-docker/templates/heal-docker.timer.j2 deleted file mode 100644 index b04d6c80..00000000 --- a/roles/heal-docker/templates/heal-docker.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=starts heal-docker.service - -[Timer] -OnCalendar={{on_calendar_heal_docker}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=false - -[Install] -WantedBy=timers.target diff --git a/roles/health-btrfs/handlers/main.yml b/roles/health-btrfs/handlers/main.yml index e8e58df6..6a2a7978 100644 --- a/roles/health-btrfs/handlers/main.yml +++ b/roles/health-btrfs/handlers/main.yml @@ -2,10 +2,4 @@ systemd: name: health-btrfs.service enabled: yes - daemon_reload: yes -- name: "restart health-btrfs.timer" - systemd: - name: health-btrfs.timer - state: restarted - enabled: yes - daemon_reload: yes + daemon_reload: yes \ No newline at end of file diff --git a/roles/health-btrfs/tasks/main.yml b/roles/health-btrfs/tasks/main.yml index cc7d27fc..30eb8300 100644 --- a/roles/health-btrfs/tasks/main.yml +++ b/roles/health-btrfs/tasks/main.yml @@ -15,10 +15,12 @@ dest: /etc/systemd/system/health-btrfs.service notify: reload health-btrfs.service -- name: create health-btrfs.timer - template: - src: health-btrfs.timer.j2 - dest: "/etc/systemd/system/health-btrfs.timer" - register: health_btrs_timer - changed_when: health_btrs_timer.changed or activate_all_timers | bool - notify: restart health-btrfs.timer +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_health_btrfs}}" diff --git a/roles/health-btrfs/templates/health-btrfs.timer.j2 b/roles/health-btrfs/templates/health-btrfs.timer.j2 deleted file mode 100644 index 787caaeb..00000000 --- a/roles/health-btrfs/templates/health-btrfs.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=starts health-btrfs.service - -[Timer] -OnCalendar={{on_calendar_health_btrfs}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=false - -[Install] -WantedBy=timers.target diff --git a/roles/health-disc-space/handlers/main.yml b/roles/health-disc-space/handlers/main.yml index dab3031d..736936c7 100644 --- a/roles/health-disc-space/handlers/main.yml +++ b/roles/health-disc-space/handlers/main.yml @@ -3,9 +3,3 @@ name: health-disc-space.service enabled: yes daemon_reload: yes -- name: "restart health-disc-space.timer" - systemd: - name: health-disc-space.timer - state: restarted - enabled: yes - daemon_reload: yes diff --git a/roles/health-disc-space/tasks/main.yml b/roles/health-disc-space/tasks/main.yml index e17c0d6f..1cfb8dc1 100644 --- a/roles/health-disc-space/tasks/main.yml +++ b/roles/health-disc-space/tasks/main.yml @@ -15,10 +15,12 @@ dest: /etc/systemd/system/health-disc-space.service notify: reload health-disc-space.service -- name: create health-disc-space.timer - template: - src: health-disc-space.timer.j2 - dest: /etc/systemd/system/health-disc-space.timer - register: health_disc_space_timer - changed_when: health_disc_space_timer.changed or activate_all_timers | bool - notify: restart health-disc-space.timer +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_health_disc_space}}" \ No newline at end of file diff --git a/roles/health-disc-space/templates/health-disc-space.timer.j2 b/roles/health-disc-space/templates/health-disc-space.timer.j2 deleted file mode 100644 index 916da0f7..00000000 --- a/roles/health-disc-space/templates/health-disc-space.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=starts health-disc-space.service - -[Timer] -OnCalendar={{on_calendar_health_disc_space}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=true - -[Install] -WantedBy=timers.target diff --git a/roles/health-docker-container/handlers/main.yml b/roles/health-docker-container/handlers/main.yml index 92799520..5ffe8f44 100644 --- a/roles/health-docker-container/handlers/main.yml +++ b/roles/health-docker-container/handlers/main.yml @@ -3,9 +3,3 @@ name: health-docker-container.service enabled: yes daemon_reload: yes -- name: "restart health-docker-container.timer" - systemd: - name: health-docker-container.timer - state: restarted - enabled: yes - daemon_reload: yes diff --git a/roles/health-docker-container/tasks/main.yml b/roles/health-docker-container/tasks/main.yml index 8fc8182a..4ced72e3 100644 --- a/roles/health-docker-container/tasks/main.yml +++ b/roles/health-docker-container/tasks/main.yml @@ -16,13 +16,16 @@ notify: reload health-docker-container.service when: run_once_health_docker_container is not defined -- name: create health-docker-container.timer - template: - src: health-docker-container.timer.j2 - dest: "/etc/systemd/system/health-docker-container.timer" - register: health_docker_container_timer - changed_when: health_docker_container_timer.changed or activate_all_timers | bool - notify: restart health-docker-container.timer +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + when: run_once_health_docker_container is not defined + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_health_docker_container}}" when: run_once_health_docker_container is not defined - name: run the health_docker_container tasks once diff --git a/roles/health-docker-container/templates/health-docker-container.timer.j2 b/roles/health-docker-container/templates/health-docker-container.timer.j2 deleted file mode 100644 index 3ae7d663..00000000 --- a/roles/health-docker-container/templates/health-docker-container.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=starts health-docker-container.service - -[Timer] -OnCalendar={{on_calendar_health_docker_container}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=false - -[Install] -WantedBy=timers.target diff --git a/roles/health-docker-volumes/handlers/main.yml b/roles/health-docker-volumes/handlers/main.yml index a1983127..6b8f0542 100644 --- a/roles/health-docker-volumes/handlers/main.yml +++ b/roles/health-docker-volumes/handlers/main.yml @@ -3,9 +3,3 @@ name: health-docker-volumes.service enabled: yes daemon_reload: yes -- name: "restart health-docker-volumes.timer" - systemd: - name: health-docker-volumes.timer - state: restarted - enabled: yes - daemon_reload: yes diff --git a/roles/health-docker-volumes/tasks/main.yml b/roles/health-docker-volumes/tasks/main.yml index dfd6838c..75049054 100644 --- a/roles/health-docker-volumes/tasks/main.yml +++ b/roles/health-docker-volumes/tasks/main.yml @@ -16,13 +16,16 @@ notify: reload health-docker-volumes.service when: run_once_health_docker_volumes is not defined -- name: create health-docker-volumes.timer - template: - src: health-docker-volumes.timer.j2 - dest: "/etc/systemd/system/health-docker-volumes.timer" - register: health_docker_volumes_timer - changed_when: health_docker_volumes_timer.changed or activate_all_timers | bool - notify: restart health-docker-volumes.timer +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + when: run_once_health_docker_volumes is not defined + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_health_docker_volumes}}" when: run_once_health_docker_volumes is not defined - name: run the health_docker_volumes tasks once diff --git a/roles/health-docker-volumes/templates/health-docker-volumes.timer.j2 b/roles/health-docker-volumes/templates/health-docker-volumes.timer.j2 deleted file mode 100644 index 634e603c..00000000 --- a/roles/health-docker-volumes/templates/health-docker-volumes.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=starts health-docker-volumes.service - -[Timer] -OnCalendar={{on_calendar_health_docker_volumes}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=false - -[Install] -WantedBy=timers.target diff --git a/roles/health-journalctl/handlers/main.yml b/roles/health-journalctl/handlers/main.yml index a1e35fb3..05bc56ea 100644 --- a/roles/health-journalctl/handlers/main.yml +++ b/roles/health-journalctl/handlers/main.yml @@ -3,9 +3,3 @@ name: health-journalctl.service enabled: yes daemon_reload: yes -- name: "restart health-journalctl.timer" - systemd: - name: health-journalctl.timer - state: restarted - enabled: yes - daemon_reload: yes diff --git a/roles/health-journalctl/tasks/main.yml b/roles/health-journalctl/tasks/main.yml index 78aaeb7b..bce20c32 100644 --- a/roles/health-journalctl/tasks/main.yml +++ b/roles/health-journalctl/tasks/main.yml @@ -3,22 +3,34 @@ path: "{{health_journalctl_folder}}" state: directory mode: 0755 + when: run_once_health_journalctl is not defined - name: create health-journalctl.sh copy: src: health-journalctl.sh dest: "{{health_journalctl_folder}}health-journalctl.sh" + when: run_once_health_journalctl is not defined - name: create health-journalctl.service template: src: health-journalctl.service.j2 dest: /etc/systemd/system/health-journalctl.service notify: reload health-journalctl.service + when: run_once_health_journalctl is not defined -- name: create health-journalctl.timer - template: - src: health-journalctl.timer.j2 - dest: /etc/systemd/system/health-journalctl.timer - register: health_journalctl_timer - changed_when: health_journalctl_timer.changed or activate_all_timers | bool - notify: restart health-journalctl.timer +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + when: run_once_health_journalctl is not defined + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_health_journalctl}}" + when: run_once_health_journalctl is not defined + +- name: run the health_journalctl tasks once + set_fact: + run_once_health_journalctl: true + when: run_once_health_journalctl is not defined \ No newline at end of file diff --git a/roles/health-journalctl/templates/health-journalctl.timer.j2 b/roles/health-journalctl/templates/health-journalctl.timer.j2 deleted file mode 100644 index 2a761db7..00000000 --- a/roles/health-journalctl/templates/health-journalctl.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=starts health-journalctl.service - -[Timer] -OnCalendar={{on_calendar_health_journalctl}} -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=false - -[Install] -WantedBy=timers.target diff --git a/roles/health-nginx/handlers/main.yml b/roles/health-nginx/handlers/main.yml index dd13fb19..73e0a0d3 100644 --- a/roles/health-nginx/handlers/main.yml +++ b/roles/health-nginx/handlers/main.yml @@ -3,10 +3,3 @@ name: health-nginx.service enabled: yes daemon_reload: yes - -- name: "restart health-nginx.timer" - systemd: - name: health-nginx.timer - state: restarted - enabled: yes - daemon_reload: yes diff --git a/roles/health-nginx/tasks/main.yml b/roles/health-nginx/tasks/main.yml index 7810ef3d..809f7c34 100644 --- a/roles/health-nginx/tasks/main.yml +++ b/roles/health-nginx/tasks/main.yml @@ -24,13 +24,16 @@ notify: reload health-nginx.service when: run_once_health_nginx is not defined -- name: create health-nginx.timer - template: - src: health-nginx.timer.j2 - dest: "/etc/systemd/system/health-nginx.timer" - register: health_nginx_timer - changed_when: health_nginx_timer.changed or activate_all_timers | bool - notify: restart health-nginx.timer +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + when: run_once_health_nginx is not defined + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_health_nginx}}" when: run_once_health_nginx is not defined - name: run the health_nginx tasks once diff --git a/roles/health-nginx/templates/health-nginx.timer.j2 b/roles/health-nginx/templates/health-nginx.timer.j2 deleted file mode 100644 index 7daefd52..00000000 --- a/roles/health-nginx/templates/health-nginx.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=starts health-nginx.service - -[Timer] -OnCalendar={{ on_calendar_health_nginx }} -RandomizedDelaySec={{ randomized_delay_sec }} -Persistent=false - -[Install] -WantedBy=timers.target \ No newline at end of file diff --git a/roles/nginx-certbot/handlers/main.yml b/roles/nginx-certbot/handlers/main.yml index e428b905..928dd4b5 100644 --- a/roles/nginx-certbot/handlers/main.yml +++ b/roles/nginx-certbot/handlers/main.yml @@ -1,12 +1,6 @@ - name: "reload certbot service" systemd: - name: certbot.service + name: nginx-certbot.service state: reloaded enabled: yes daemon_reload: yes -- name: "restart certbot timer" - systemd: - name: certbot.timer - state: restarted - enabled: yes - daemon_reload: yes diff --git a/roles/nginx-certbot/tasks/main.yml b/roles/nginx-certbot/tasks/main.yml index 29b5e0b9..a2f1f592 100644 --- a/roles/nginx-certbot/tasks/main.yml +++ b/roles/nginx-certbot/tasks/main.yml @@ -4,20 +4,24 @@ state: present when: run_once_nginx_certbot is not defined -- name: configure certbot.service.tpl +- name: configure nginx-certbot.service template: - src: certbot.service.j2 - dest: /etc/systemd/system/certbot.service + src: nginx-certbot.service.j2 + dest: /etc/systemd/system/nginx-certbot.service notify: reload certbot service when: run_once_nginx_certbot is not defined -- name: configure certbot.timer.tpl - template: - src: certbot.timer.j2 - dest: /etc/systemd/system/certbot.timer - register: certbot_timer - changed_when: certbot_timer.changed or activate_all_timers | bool - notify: restart certbot timer +- name: set service_name to the name of the current role + set_fact: + service_name: "{{ role_name }}" + when: run_once_nginx_certbot is not defined + +- name: "include role for systemd-timer for {{service_name}}" + include_role: + name: systemd-timer + vars: + on_calendar: "{{on_calendar_renew_lets_encrypt_certificates}}" + persistent: "true" when: run_once_nginx_certbot is not defined - name: run the nginx_certbot tasks once diff --git a/roles/nginx-certbot/templates/certbot.timer.j2 b/roles/nginx-certbot/templates/certbot.timer.j2 deleted file mode 100644 index 6b530b85..00000000 --- a/roles/nginx-certbot/templates/certbot.timer.j2 +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Renewal of Let's Encrypt's certificates - -[Timer] -OnCalendar=0/12:00:00 -RandomizedDelaySec={{randomized_delay_sec}} -Persistent=true - -[Install] -WantedBy=timers.target diff --git a/roles/nginx-certbot/templates/certbot.service.j2 b/roles/nginx-certbot/templates/nginx-certbot.service.j2 similarity index 100% rename from roles/nginx-certbot/templates/certbot.service.j2 rename to roles/nginx-certbot/templates/nginx-certbot.service.j2 diff --git a/roles/systemd-timer/templates/dummy.timer.j2 b/roles/systemd-timer/templates/dummy.timer.j2 index 8b246dd8..187dc783 100644 --- a/roles/systemd-timer/templates/dummy.timer.j2 +++ b/roles/systemd-timer/templates/dummy.timer.j2 @@ -4,7 +4,7 @@ Description=Timer to start {{service_name}}.service [Timer] OnCalendar={{on_calendar}} RandomizedDelaySec={{randomized_delay_sec}} -Persistent=false +Persistent={{ persistent | default('false') }} [Install] WantedBy=timers.target