---
- name: Update technikum pcs
  hosts: technikum-pc*
  become: true
  tasks:
    - name: Ansible Update Cache and Upgrade all Packages
      ansible.builtin.apt:
        name: "*"
        state: latest
        update_cache: yes

    - name: Check if a reboot is required
      ansible.builtin.stat:
        path: /var/run/reboot-required
      register: reboot_required
      check_mode: false

    - debug:
        msg: "Reboot required"
      when: reboot_required.stat.exists
      check_mode: false

    # prohibits a crash of the playbook due to termination of ssh connection
    - name: Reboot Machine and wait 60 sec to validate connection to machine
      ansible.builtin.reboot:
        post_reboot_delay: 60
      when: reboot_required.stat.exists
