Files
nova/roles/run-evacuate-hook/tasks/manage_libvirt_service.yaml
T
Sean Mooney 6c9110bb8b Handle missing libvirt services in evacuate hook
On Debian 13 (Trixie), libvirt packaging is modularized and
the libvirt-daemon-lock package (providing virtlockd) is
optional. The evacuate hook previously assumed all libvirt
services were installed and failed when stopping/starting
missing units.

Extract a reusable manage_libvirt_service.yaml task file that
checks if a service exists via systemctl list-unit-files
before managing its units. This prevents failures when
optional libvirt packages are not installed and future-proofs
against further packaging changes.

Generated-By: claude-code
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change-Id: Ie84e2e8ab2d3065b1562ee5e256fa163541955f7
Signed-off-by: Sean Mooney <work@seanmooney.info>
2026-02-17 18:22:22 +00:00

23 lines
726 B
YAML

# Manage a libvirt service (stop/start) only if it is installed.
# Parameters:
# service_name: base name of the service (e.g. "libvirtd", "virtlogd", "virtlockd")
# service_state: "stopped" or "started"
# service_enabled: "yes" or "no"
# service_units: list of unit names to manage
- name: "Check if {{ service_name }} is installed"
become: true
command: systemctl list-unit-files {{ service_name }}.service
register: _service_check
ignore_errors: true
changed_when: false
- name: "Manage {{ service_name }} units"
become: true
systemd:
name: "{{ item }}"
state: "{{ service_state }}"
enabled: "{{ service_enabled }}"
with_items: "{{ service_units }}"
when: _service_check is succeeded