Ansible - Reboot a system
by
Jeremy Canfield |
Updated: August 07 2024
| Ansible articles
If you are not familiar with modules, check out Ansible - Getting Started with Modules.
reboot, as the name suggests, is used to reboot a target system. In this example, 30 seconds after the reboot was initiated, there will be an attempt to SSH onto the target system and issue the whoami command to see if the host is up, keeping this up for 600 seconds (10 minutes).
AVOID TROUBLE
reboot can only be run by root or by a user or group that has been granted sudo permission to the reboot command, because the reboot command is within the sbin directory (e.g. /usr/sbin/reboot). Refer to Ansible - become (sudo) for the steps on how to grant a user or group become (sudo) permission to the reboot command.
---
- hosts: all
tasks:
- name: reboot OS
ansible.builtin.reboot:
msg: "Reboot initiated by Ansible"
connect_timeout: 5
reboot_timeout: 600
pre_reboot_delay: 0
post_reboot_delay: 30
test_command: whoami
...
Did you find this article helpful?
If so, consider buying me a coffee over at