ansible: add reboot playbook and short hostname support
- Add reboot.yml playbook with rolling reboot (serial: 1) - Uses systemd reboot.target for NixOS compatibility - Waits for each host to come back before proceeding - Update dynamic inventory to use short hostnames - ansible_host set to FQDN for connections - Allows -l testvm01 instead of -l testvm01.home.2rjus.net - Update static.yml to match short hostname convention Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
48
ansible/playbooks/reboot.yml
Normal file
48
ansible/playbooks/reboot.yml
Normal file
@@ -0,0 +1,48 @@
|
||||
---
|
||||
# Reboot hosts with rolling strategy to avoid taking down redundant services
|
||||
#
|
||||
# Usage examples:
|
||||
# # Reboot a single host
|
||||
# ansible-playbook reboot.yml -l testvm01
|
||||
#
|
||||
# # Reboot all test hosts (one at a time)
|
||||
# ansible-playbook reboot.yml -l tier_test
|
||||
#
|
||||
# # Reboot all DNS servers safely (one at a time)
|
||||
# ansible-playbook reboot.yml -l role_dns
|
||||
#
|
||||
# Safety features:
|
||||
# - serial: 1 ensures only one host reboots at a time
|
||||
# - Waits for host to come back online before proceeding
|
||||
# - Groups hosts by role to avoid rebooting same-role hosts consecutively
|
||||
|
||||
- name: Reboot hosts (rolling)
|
||||
hosts: all
|
||||
serial: 1
|
||||
order: shuffle # Randomize to spread out same-role hosts
|
||||
gather_facts: false
|
||||
|
||||
vars:
|
||||
reboot_timeout: 300 # 5 minutes to wait for host to come back
|
||||
|
||||
tasks:
|
||||
- name: Display reboot target
|
||||
ansible.builtin.debug:
|
||||
msg: "Rebooting {{ inventory_hostname }} (role: {{ role | default('none') }})"
|
||||
|
||||
- name: Reboot the host
|
||||
ansible.builtin.systemd:
|
||||
name: reboot.target
|
||||
state: started
|
||||
async: 1
|
||||
poll: 0
|
||||
ignore_errors: true
|
||||
|
||||
- name: Wait for host to come back online
|
||||
ansible.builtin.wait_for_connection:
|
||||
delay: 5
|
||||
timeout: "{{ reboot_timeout }}"
|
||||
|
||||
- name: Display reboot result
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ inventory_hostname }} rebooted successfully"
|
||||
Reference in New Issue
Block a user