diff --git a/roles/apt_update_and_upgrade/handlers/main.yaml b/roles/apt_update_and_upgrade/handlers/main.yaml index 515d980..4af18be 100644 --- a/roles/apt_update_and_upgrade/handlers/main.yaml +++ b/roles/apt_update_and_upgrade/handlers/main.yaml @@ -1,6 +1,5 @@ - name: reboot the system - ansible.builtin.import_role: - role: reboot + ansible.builtin.include_tasks: "../../reboot/tasks/main.yaml" vars: # Simply don't reboot on local connections and rely on proper handling of /var/run/reboot-required. reboot__local_handling: ignore diff --git a/roles/reboot/README.md b/roles/reboot/README.md index 184b418..1aaa6a6 100644 --- a/roles/reboot/README.md +++ b/roles/reboot/README.md @@ -10,3 +10,17 @@ A role for rebooting a host, which also handles local connections gracefully. - `ignore`: Just doesn't reboot on local connections. - `file`: Doesn't reboot on local connections and instead touches the file defined by `reboot__local_handling_file`. - `reboot__local_handling_file`: The file to touch, if `reboot__local_handling` is `file`. Defaults to `/var/run/ansible-reboot-required`. + +## Usage in a Handler + +Since a reboot should often be triggered from a handler and since handlers can't include or import roles, this roles logic can also be run by including the `main.yaml` task using `ansible.builtin.include_tasks` as a workaround. +When doing so, arguments should be specified explicitly as necessary (so at least `reboot__local_handling`) as the default role inclusion mechanisms like setting default values don't work. + +An example handler would look like this: + +```yaml +- name: reboot the system + ansible.builtin.include_tasks: "../../reboot/tasks/main.yaml" + vars: + reboot__local_handling: ignore +```