Skip to content

Commit

Permalink
Merge pull request #4 from mjourdan/feat_reboot
Browse files Browse the repository at this point in the history
Feat reboot
  • Loading branch information
exploide authored May 7, 2022
2 parents 96bee72 + ba3b6a8 commit a736a7b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ This default configuration sets `dnf-automatic` up to automatically download and

Note that the `dnf_automatic_base_overrides` dictionary can be used to override arbitrary preferences from the base dnf configuration file for `dnf-automatic`.

In addition, `dnf_automatic_reboot` can be set to true to perform automatic reboots when installed updates require it:

```yaml
dnf_automatic_reboot: false
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
------------

Expand All @@ -56,6 +67,16 @@ This example playbook deploys `dnf-automatic` on all hosts but is configured suc
- { role: exploide.dnf-automatic, dnf_automatic_upgrade_type: default }
```

This example playbook deploys `dnf-automatic` to install security updates only, and deploys additional timer to reboot at 4:00 am when required:

```yaml
- hosts: all
remote_user: root
roles:
- { role: exploide.dnf-automatic, dnf_automatic_reboot: true, dnf_automatic_reboot_time: "04:00" }
```


License
-------

Expand Down
9 changes: 9 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ dnf_automatic_email_host: localhost

# this dict can be used to override arbitrary settings from dnf.conf
dnf_automatic_base_overrides: {}

# Reboot

dnf_automatic_reboot: false
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'
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ galaxy_info:
- name: EL
versions:
- 7
- 8
- name: Fedora
versions:
- all
Expand Down
29 changes: 29 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,32 @@
name: dnf-automatic-install.timer
state: started
enabled: yes

- 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

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 a736a7b

Please sign in to comment.