Skip to content

Commit c90c04e

Browse files
authored
M #-: Redo virtqemud disabler (fix) (#89)
- Do not use the service_facts module as it's limited to services only and seems to be unreasonably slow. - Improve error handling for each involved systemd unit. - Disable virtqemud's sockets only.
1 parent 15defee commit c90c04e

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

roles/kvm/tasks/libvirt.yml

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88

99
- name: Restart libvirtd (NOW)
1010
ansible.builtin.service:
11-
name: "{{ _name[ansible_os_family] }}"
11+
name: libvirtd
1212
state: restarted
13-
vars:
14-
_name:
15-
Debian: libvirtd
16-
RedHat: libvirtd
1713
when: lineinfile is changed
1814

1915
- name: Disable Libvirt's default network (optional)
@@ -28,30 +24,31 @@
2824
changed_when: false
2925
when: disable_default_net | bool is true
3026

31-
- name: Populate service facts
32-
ansible.builtin.service_facts:
27+
- name: Query raw status of virtqemud.service
28+
ansible.builtin.systemd:
29+
name: virtqemud.service
30+
register: systemd_virtqemud
3331
no_log: true
3432

3533
# NOTE: OpenNebula cannot deal with socket-activated Libvirt (yet),
36-
# so the socket activation *MUST* be disabled.
37-
- when: ansible_facts.services is contains('virtqemud.service')
34+
# so the socket activation *MUST* be disabled.
35+
- when: systemd_virtqemud.status.LoadState not in ['masked', 'not-found']
3836
block:
3937
- name: Mask virtqemud* units and libvirtd* sockets
4038
ansible.builtin.systemd:
4139
name: "{{ item }}"
4240
enabled: false
4341
masked: true
4442
state: stopped
43+
register: result
44+
failed_when:
45+
- result is failed
46+
- result.status.LoadState is defined and result.status.LoadState != 'not-found'
4547
loop:
4648
- virtqemud.service
4749
- virtqemud.socket
4850
- virtqemud-admin.socket
4951
- virtqemud-ro.socket
50-
- libvirtd.socket
51-
- libvirtd-admin.socket
52-
- libvirtd-ro.socket
53-
- libvirtd-tcp.socket
54-
- libvirtd-tls.socket
5552

5653
- name: Create /etc/systemd/system/libvirtd.service.d/
5754
ansible.builtin.file:
@@ -100,9 +97,9 @@
10097
get_attributes: false
10198
get_checksum: false
10299
get_mime: false
103-
register: stat_libvirt_qemu
100+
register: stat
104101

105-
- when: stat_libvirt_qemu.stat.exists is true
102+
- when: stat.stat.exists is true
106103
block:
107104
- name: Add permissions to AppArmor
108105
ansible.builtin.lineinfile:
@@ -111,7 +108,7 @@
111108
loop:
112109
- " /srv/** rwk,"
113110
- " /var/lib/one/datastores/** rwk,"
114-
register: lineinfile_libvirt_qemu
111+
register: lineinfile
115112

116113
- name: Reload apparmor
117114
ansible.builtin.service:
@@ -122,4 +119,4 @@
122119
- result is failed
123120
- result.msg is not contains("find")
124121
- result.msg is not contains("found")
125-
when: lineinfile_libvirt_qemu is changed
122+
when: lineinfile is changed

0 commit comments

Comments
 (0)