summaryrefslogtreecommitdiff
path: root/deploy-reboot.yml
blob: de7bed77cf521f13ac38a7383c55b60d0698df68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
- name: Deploy conditional reboot service and timer
  hosts: all
  become: yes

  tasks:
    - name: Copy conditional-reboot.service file
      copy:
        dest: /etc/systemd/system/conditional-reboot.service
        content: |
          [Unit]
          Description=Service to conditionally reboot the system if /var/run/reboot-required exists

          [Service]
          Type=oneshot
          ExecStart=/bin/sh -c 'if [ -f /var/run/reboot-required ]; then reboot; fi'
      notify:
        - reload systemd

    - name: Copy conditional-reboot.timer file
      copy:
        dest: /etc/systemd/system/conditional-reboot.timer
        content: |
          [Unit]
          Description=Timer to run conditional reboot service daily at 1:30 AM

          [Timer]
          OnCalendar=daily 01:30:00
          Persistent=true

          [Install]
          WantedBy=timers.target
      notify:
        - reload systemd

    - name: Enable and start conditional-reboot.timer
      systemd:
        name: conditional-reboot.timer
        enabled: yes
        state: started

  handlers:
    - name: reload systemd
      systemd:
        daemon_reload: yes