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>
This commit is contained in:
@@ -48,23 +48,30 @@
|
|||||||
state: destroyed
|
state: destroyed
|
||||||
with_items: "{{ subnode_vms.list_vms }}"
|
with_items: "{{ subnode_vms.list_vms }}"
|
||||||
|
|
||||||
- name: Stop libvirtd on "{{ inventory_hostname }}"
|
- name: Stop libvirt services on "{{ inventory_hostname }}"
|
||||||
become: true
|
include_tasks: manage_libvirt_service.yaml
|
||||||
systemd:
|
vars:
|
||||||
name: "{{ item }}"
|
service_name: "{{ item.name }}"
|
||||||
state: stopped
|
service_state: stopped
|
||||||
enabled: no
|
service_enabled: "no"
|
||||||
with_items:
|
service_units: "{{ item.units }}"
|
||||||
- libvirtd.service
|
loop:
|
||||||
- libvirtd.socket
|
- name: libvirtd
|
||||||
- libvirtd-admin.socket
|
units:
|
||||||
- libvirtd-ro.socket
|
- libvirtd.service
|
||||||
- virtlogd.service
|
- libvirtd.socket
|
||||||
- virtlogd-admin.socket
|
- libvirtd-admin.socket
|
||||||
- virtlogd.socket
|
- libvirtd-ro.socket
|
||||||
- virtlockd.service
|
- name: virtlogd
|
||||||
- virtlockd-admin.socket
|
units:
|
||||||
- virtlockd.socket
|
- virtlogd.service
|
||||||
|
- virtlogd-admin.socket
|
||||||
|
- virtlogd.socket
|
||||||
|
- name: virtlockd
|
||||||
|
units:
|
||||||
|
- virtlockd.service
|
||||||
|
- virtlockd-admin.socket
|
||||||
|
- virtlockd.socket
|
||||||
|
|
||||||
- name: Run negative evacuate tests
|
- name: Run negative evacuate tests
|
||||||
become: true
|
become: true
|
||||||
@@ -73,23 +80,30 @@
|
|||||||
environment:
|
environment:
|
||||||
CONTROLLER_HOSTNAME: "{{ hostvars['controller']['ansible_hostname'] }}"
|
CONTROLLER_HOSTNAME: "{{ hostvars['controller']['ansible_hostname'] }}"
|
||||||
|
|
||||||
- name: Start libvirtd on "{{ inventory_hostname }}"
|
- name: Start libvirt services on "{{ inventory_hostname }}"
|
||||||
become: true
|
include_tasks: manage_libvirt_service.yaml
|
||||||
systemd:
|
vars:
|
||||||
name: "{{ item }}"
|
service_name: "{{ item.name }}"
|
||||||
state: started
|
service_state: started
|
||||||
enabled: yes
|
service_enabled: "yes"
|
||||||
with_items:
|
service_units: "{{ item.units }}"
|
||||||
- libvirtd.service
|
loop:
|
||||||
- libvirtd.socket
|
- name: libvirtd
|
||||||
- libvirtd-admin.socket
|
units:
|
||||||
- libvirtd-ro.socket
|
- libvirtd.service
|
||||||
- virtlogd.service
|
- libvirtd.socket
|
||||||
- virtlogd-admin.socket
|
- libvirtd-admin.socket
|
||||||
- virtlogd.socket
|
- libvirtd-ro.socket
|
||||||
- virtlockd.service
|
- name: virtlogd
|
||||||
- virtlockd-admin.socket
|
units:
|
||||||
- virtlockd.socket
|
- virtlogd.service
|
||||||
|
- virtlogd-admin.socket
|
||||||
|
- virtlogd.socket
|
||||||
|
- name: virtlockd
|
||||||
|
units:
|
||||||
|
- virtlockd.service
|
||||||
|
- virtlockd-admin.socket
|
||||||
|
- virtlockd.socket
|
||||||
|
|
||||||
- name: Run evacuate tests
|
- name: Run evacuate tests
|
||||||
become: true
|
become: true
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# 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
|
||||||
Reference in New Issue
Block a user