Also use this role instead of plain ansible.builtin.reboot. This is in preparation for using ansible_pull as we don't want to have ansible.builtin.reboot fail local playbook runs.
1.2 KiB
1.2 KiB
Role reboot
A role for rebooting a host, which also handles local connections gracefully.
Optional Arguments
reboot__local_handling
: How to handle reboot on local connections. The default mode isnone
.
Possible choices:none
: Just runsansible.builtin.reboot
, which would fail on local connections.ignore
: Just doesn't reboot on local connections.file
: Doesn't reboot on local connections and instead touches the file defined byreboot__local_handling_file
.
reboot__local_handling_file
: The file to touch, ifreboot__local_handling
isfile
. 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:
- name: reboot the system
ansible.builtin.include_tasks: "../../reboot/tasks/main.yaml"
vars:
reboot__local_handling: ignore