Skip to content

Commit

Permalink
drop external dependencies and unnecessary script
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Jourdan committed May 6, 2022
1 parent 957a03d commit ba3b6a8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 36 deletions.
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------
Expand Down
10 changes: 4 additions & 6 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
8 changes: 1 addition & 7 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
36 changes: 26 additions & 10 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions templates/dnf-automatic-reboot.service
Original file line number Diff line number Diff line change
@@ -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 }}
11 changes: 11 additions & 0 deletions templates/dnf-automatic-reboot.timer
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ba3b6a8

Please sign in to comment.