From ba3b6a8b44367b637060d7001f92338f832cf94d Mon Sep 17 00:00:00 2001 From: Mathieu Jourdan Date: Fri, 6 May 2022 16:55:55 +0200 Subject: [PATCH] drop external dependencies and unnecessary script --- README.md | 18 ++++--------- defaults/main.yml | 10 +++---- meta/main.yml | 8 +----- tasks/main.yml | 36 +++++++++++++++++++------- templates/dnf-automatic-reboot.service | 8 ++++++ templates/dnf-automatic-reboot.timer | 11 ++++++++ 6 files changed, 55 insertions(+), 36 deletions(-) create mode 100644 templates/dnf-automatic-reboot.service create mode 100644 templates/dnf-automatic-reboot.timer diff --git a/README.md b/README.md index 205506b..079d1ef 100644 --- a/README.md +++ b/README.md @@ -43,25 +43,17 @@ In addition, `dnf_automatic_reboot` can be set to true to perform automatic rebo ```yaml dnf_automatic_reboot: false -dnf_automatic_reboot_time: "03:00" -dnf_automatic_reboot_script: "/usr/local/sbin/reboot-when-needed.sh" -dnf_automatic_reboot_script_mode: "0700" -dnf_automatic_reboot_script_content: | - #!/bin/bash - /bin/needs-restarting -r || /sbin/reboot dnf_automatic_reboot_dependencies: yum-utils +dnf_automatic_reboot_OnCalendar: "03:00" +dnf_automatic_reboot_AccuracySec: "15s" +dnf_automatic_reboot_Description: "dnf-automatic-reboot" +dnf_automatic_reboot_ExecStart: /bin/bash -c '/bin/needs-restarting -r || /sbin/reboot' ``` Dependencies ------------ -This role has a dependency on `vlcty.systemd-timers` to periodically run the reboot script. It can be installed by adding the following block to roles/requirements.yml: - -``` -- src: https://github.com/vlcty/ansible-systemd-timers.git - name: vlcty.systemd-timers - scm: git -``` +No dependencies needed. Example Playbook ---------------- diff --git a/defaults/main.yml b/defaults/main.yml index 210a4c4..2f3f7ac 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -39,10 +39,8 @@ dnf_automatic_base_overrides: {} # Reboot dnf_automatic_reboot: false -dnf_automatic_reboot_time: "03:00" -dnf_automatic_reboot_script: "/usr/local/sbin/reboot-when-needed.sh" -dnf_automatic_reboot_script_mode: "0700" -dnf_automatic_reboot_script_content: | - #!/bin/bash - /bin/needs-restarting -r || /sbin/reboot dnf_automatic_reboot_dependencies: yum-utils +dnf_automatic_reboot_OnCalendar: "03:00" +dnf_automatic_reboot_AccuracySec: "15s" +dnf_automatic_reboot_Description: "dnf-automatic-reboot" +dnf_automatic_reboot_ExecStart: /bin/bash -c '/bin/needs-restarting -r || /sbin/reboot' diff --git a/meta/main.yml b/meta/main.yml index 0460e81..2d2885c 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -20,10 +20,4 @@ galaxy_info: - packaging - system -dependencies: - - role: vlcty.systemd-timers - timers: - dnf-automatic-reboot: - timer_command: "{{ dnf_automatic_reboot_script }}" - timer_OnCalendar: "{{ dnf_automatic_reboot_time }}" - when: dnf_automatic_reboot +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml index 40ae022..4490ed7 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -16,15 +16,31 @@ state: started enabled: yes -- name: Install dependencies needed for reboot - package: - name: "{{ dnf_automatic_reboot_dependencies }}" - state: present - when: dnf_automatic_reboot|bool +- block: + + - name: Install dependencies needed for reboot + package: + name: "{{ dnf_automatic_reboot_dependencies }}" + state: present + tags: pkg + + - name: Deploy service and timer units + template: + src: "{{ item }}" + dest: "/etc/systemd/system/{{ item }}" + owner: root + group: root + mode: 0640 + loop: + - dnf-automatic-reboot.service + - dnf-automatic-reboot.timer -- name: Copy reboot script - copy: - dest: "{{ dnf_automatic_reboot_script }}" - content: "{{ dnf_automatic_reboot_script_content }}" - mode: "{{ dnf_automatic_reboot_script_mode }}" when: dnf_automatic_reboot|bool + +- name: Set timer state for auto reboot + systemd: + name: dnf-automatic-reboot.timer + state: "{{ dnf_automatic_reboot | ternary ('started', 'stopped') }}" + enabled: "{{ dnf_automatic_reboot }}" + masked: false + daemon_reload: true diff --git a/templates/dnf-automatic-reboot.service b/templates/dnf-automatic-reboot.service new file mode 100644 index 0000000..d6092e6 --- /dev/null +++ b/templates/dnf-automatic-reboot.service @@ -0,0 +1,8 @@ +# Managed by ansible - role dnf-automatic + +[Unit] +Description={{ dnf_automatic_reboot_Description }} service + +[Service] +Type=oneshot +ExecStart={{ dnf_automatic_reboot_ExecStart }} diff --git a/templates/dnf-automatic-reboot.timer b/templates/dnf-automatic-reboot.timer new file mode 100644 index 0000000..836af5a --- /dev/null +++ b/templates/dnf-automatic-reboot.timer @@ -0,0 +1,11 @@ +# Managed by ansible - role dnf-automatic + +[Unit] +Description={{ dnf_automatic_reboot_Description }} timer + +[Timer] +OnCalendar={{ dnf_automatic_reboot_OnCalendar }} +AccuracySec={{ dnf_automatic_reboot_AccuracySec }} + +[Install] +WantedBy=timers.target