- Move playbooks/ to ansible/playbooks/ - Add dynamic inventory script that extracts hosts from flake - Groups by tier (tier_test, tier_prod) and role (role_dns, etc.) - Reads homelab.host.* options for metadata - Add static inventory for non-flake hosts (Proxmox) - Add ansible.cfg with inventory path and SSH optimizations - Add group_vars/all.yml for common variables - Add restart-service.yml playbook for restarting systemd services - Update provision-approle.yml with single-host safeguard - Add ANSIBLE_CONFIG to devshell for automatic inventory discovery - Add ansible = "false" label to template2 to exclude from inventory - Update CLAUDE.md to reference ansible/README.md for details Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
41 lines
1.1 KiB
YAML
41 lines
1.1 KiB
YAML
---
|
|
# Restart a systemd service on target hosts
|
|
#
|
|
# Usage examples:
|
|
# # Restart unbound on all DNS servers
|
|
# ansible-playbook restart-service.yml -l role_dns -e service=unbound
|
|
#
|
|
# # Restart nginx on a specific host
|
|
# ansible-playbook restart-service.yml -l http-proxy.home.2rjus.net -e service=nginx
|
|
#
|
|
# # Restart promtail on all prod hosts
|
|
# ansible-playbook restart-service.yml -l tier_prod -e service=promtail
|
|
|
|
- name: Restart systemd service
|
|
hosts: all
|
|
gather_facts: false
|
|
|
|
tasks:
|
|
- name: Validate service name provided
|
|
ansible.builtin.fail:
|
|
msg: |
|
|
The 'service' variable is required.
|
|
Usage: ansible-playbook restart-service.yml -l <target> -e service=<name>
|
|
|
|
Examples:
|
|
-e service=nginx
|
|
-e service=unbound
|
|
-e service=promtail
|
|
when: service is not defined
|
|
run_once: true
|
|
|
|
- name: Restart {{ service }}
|
|
ansible.builtin.systemd:
|
|
name: "{{ service }}"
|
|
state: restarted
|
|
register: restart_result
|
|
|
|
- name: Display result
|
|
ansible.builtin.debug:
|
|
msg: "Service {{ service }} restarted on {{ inventory_hostname }}"
|