Skip to content

Commit 1152fc6

Browse files
committed
libvirt: make it possible to run libvirt on the host
In some cases it may be desirable to run the libvirt daemon on the host. For example, when mixing host and container OS distributions or versions. This change implements changes to the baremetal role necessary to disable the nova_libvirt container. In this case we should not remove libvirt packages from the host, nor should we remove the AppArmor profile for libvirt on Ubuntu hosts. Needed-By: https://review.opendev.org/c/openstack/kolla-ansible/+/825357 Change-Id: I8dbe805cea66bd04374b36a4e8876da9b05b2045 (cherry picked from commit efd3335f6d8add0a4bf15f98bb744e990352bbfb)
1 parent af02e6e commit 1152fc6

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

ansible/roles/baremetal/defaults/main.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ redhat_pkg_install:
6868
ubuntu_pkg_removals:
6969
- lxd
7070
- lxc
71-
- libvirt-bin
71+
- "{% if enable_nova_libvirt_container | bool %}libvirt-bin{% endif %}"
7272
- open-iscsi
7373
- "{% if enable_chrony | bool %}chrony{% endif %}"
7474

7575
redhat_pkg_removals:
76-
- libvirt
77-
- libvirt-daemon
76+
- "{% if enable_nova_libvirt_container | bool %}libvirt{% endif %}"
77+
- "{% if enable_nova_libvirt_container | bool %}libvirt-daemon{% endif %}"
7878
- iscsi-initiator-utils
7979
- "{% if enable_chrony | bool %}chrony{% endif %}"
8080

@@ -86,3 +86,6 @@ virtualenv:
8686
# directory. This is typically required for modules such as yum and apt which
8787
# are not available on PyPI.
8888
virtualenv_site_packages: True
89+
90+
# Whether to remove the AppArmor libvirt profile on Ubuntu hosts.
91+
apparmor_remove_libvirt_profile: "{{ enable_nova_libvirt_container | bool }}"

ansible/roles/baremetal/tasks/post-install.yml

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,29 +188,30 @@
188188
daemon_reload: yes
189189
register: docker_reloaded
190190

191-
- name: Get stat of libvirtd apparmor profile
192-
stat:
193-
path: /etc/apparmor.d/usr.sbin.libvirtd
194-
register: apparmor_libvirtd_profile
195-
when: ansible_facts.distribution == "Ubuntu"
196-
197-
- name: Get stat of libvirtd apparmor disable profile
198-
stat:
199-
path: /etc/apparmor.d/disable/usr.sbin.libvirtd
200-
register: apparmor_libvirtd_disable_profile
201-
when: ansible_facts.distribution == "Ubuntu"
202-
203-
- name: Remove apparmor profile for libvirt
204-
shell: |
205-
apparmor_parser -v -R /etc/apparmor.d/usr.sbin.libvirtd && \
206-
ln -vsf /etc/apparmor.d/usr.sbin.libvirtd /etc/apparmor.d/disable
207-
args:
208-
executable: /bin/bash
209-
become: True
191+
- block:
192+
- name: Get stat of libvirtd apparmor profile
193+
stat:
194+
path: /etc/apparmor.d/usr.sbin.libvirtd
195+
register: apparmor_libvirtd_profile
196+
197+
- name: Get stat of libvirtd apparmor disable profile
198+
stat:
199+
path: /etc/apparmor.d/disable/usr.sbin.libvirtd
200+
register: apparmor_libvirtd_disable_profile
201+
202+
- name: Remove apparmor profile for libvirt
203+
shell: |
204+
apparmor_parser -v -R /etc/apparmor.d/usr.sbin.libvirtd && \
205+
ln -vsf /etc/apparmor.d/usr.sbin.libvirtd /etc/apparmor.d/disable
206+
args:
207+
executable: /bin/bash
208+
become: True
209+
when:
210+
- apparmor_libvirtd_profile.stat.exists
211+
- not apparmor_libvirtd_disable_profile.stat.exists
210212
when:
211213
- ansible_facts.distribution == "Ubuntu"
212-
- apparmor_libvirtd_profile.stat.exists
213-
- not apparmor_libvirtd_disable_profile.stat.exists
214+
- apparmor_remove_libvirt_profile | bool
214215

215216
- name: Get stat of chronyd apparmor profile
216217
stat:

0 commit comments

Comments
 (0)