# Reboot decision and execution. # Determines whether a reboot is needed because a new kernel was installed, # performs the reboot asynchronously, waits for the host to come back, and # records timing facts for the update log. - name: Gather running kernel command: uname -r register: os_update_running_kernel changed_when: false when: ansible_facts['virtualization_type'] != 'lxc' - name: Gather latest installed kernel shell: | dpkg -l | grep -E '^ii' | grep 'linux-image-[0-9]' | awk '{print $2}' | sort | tail -n 1 register: os_update_latest_kernel changed_when: false failed_when: false when: ansible_facts['virtualization_type'] != 'lxc' - name: Determine reboot decision set_fact: os_update_reboot_required: true os_update_reboot_reason: "new kernel installed ({{ os_update_running_kernel.stdout }} -> {{ os_update_latest_kernel.stdout | regex_replace('^linux-image-', '') }})" when: - ansible_facts['virtualization_type'] != 'lxc' - os_update_latest_kernel.stdout | length > 0 - os_update_running_kernel.stdout not in os_update_latest_kernel.stdout - name: Default reboot decision to false set_fact: os_update_reboot_required: "{{ os_update_reboot_required | default(false) }}" os_update_reboot_reason: "{{ os_update_reboot_reason | default('none') }}" - name: Default reboot timing facts set_fact: os_update_reboot_triggered: false os_update_reboot_start_iso: "n/a" os_update_reboot_downtime_seconds: 0 os_update_running_kernel_after: "{{ os_update_running_kernel.stdout | default('n/a') }}" - block: - name: Reboot - Record start time command: date -Iseconds register: os_update_reboot_start_iso_raw changed_when: false - name: Reboot - Record start epoch command: date +%s register: os_update_reboot_start_ts changed_when: false - name: Reboot - Reboot system command: /sbin/reboot async: 1 poll: 0 ignore_errors: true - name: Reboot - Wait for host to come back online wait_for_connection: delay: 10 timeout: 600 register: os_update_reboot_wait - name: Reboot - Record end epoch command: date +%s register: os_update_reboot_end_ts changed_when: false - name: Reboot - Compute downtime set_fact: os_update_reboot_downtime_seconds: "{{ (os_update_reboot_end_ts.stdout | int) - (os_update_reboot_start_ts.stdout | int) }}" - name: Reboot - Gather running kernel after reboot command: uname -r register: os_update_running_kernel_after_raw changed_when: false - name: Reboot - Record reboot facts set_fact: os_update_reboot_triggered: true os_update_reboot_start_iso: "{{ os_update_reboot_start_iso_raw.stdout }}" os_update_running_kernel_after: "{{ os_update_running_kernel_after_raw.stdout }}" when: os_update_reboot_required | bool