From 1c471b0ea0315860bb482c017b60ec6d120f30a5 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Mon, 1 Jun 2020 15:15:00 +0200 Subject: [PATCH] Raspbian: Handle reboot with molly-guard and older Ansible versions --- tasks/setup-debian-raspbian.yml | 47 +++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/tasks/setup-debian-raspbian.yml b/tasks/setup-debian-raspbian.yml index 7fb889f..8e7214b 100644 --- a/tasks/setup-debian-raspbian.yml +++ b/tasks/setup-debian-raspbian.yml @@ -26,23 +26,60 @@ apt: name: - "raspberrypi-kernel" - state: present + state: latest register: kernel_update tags: - wg-install -- name: (Raspbian) Reboot after kernel update +- name: (Raspbian) Reboot after kernel update (Ansible >= 2.8) reboot: search_paths: ['/lib/molly-guard', '/usr/sbin'] - when: kernel_update is changed + when: + - ansible_version.full is version('2.8.0', '>=') + - kernel_update is changed tags: - wg-install -- name: (Raspbian) Install kernel headers to compile Wireguard with DKMS +- name: (Raspbian) Check if molly-guard is installed (Ansible < 2.8) + stat: + path: /lib/molly-guard/ + register: molly_guard + +- name: (Raspbian) Reboot after kernel update (Ansible < 2.8, no molly-guard) + reboot: + when: + - ansible_version.full is version('2.8.0', '<') + - kernel_update is changed + - not molly_guard.stat.exists + tags: + - wg-install + +- name: (Raspbian) Reboot after kernel update (Ansible < 2.8, with molly-guard) + command: /lib/molly-guard/shutdown -r now + async: 1 + poll: 0 + ignore_unreachable: yes + when: + - ansible_version.full is version('2.8.0', '<') + - kernel_update is changed + - molly_guard.stat.exists + tags: + - wg-install + +- name: (Raspbian) Waiting for host to be available (Ansible < 2.8, with molly-guard) + wait_for_connection: + when: + - ansible_version.full is version('2.8.0', '<') + - kernel_update is changed + - molly_guard.stat.exists + tags: + - wg-install + +- name: (Raspbian) Install latest kernel headers to compile Wireguard with DKMS apt: name: - "raspberrypi-kernel-headers" - state: present + state: latest tags: - wg-install