2023-09-01 15:42:19 -04:00
|
|
|
---
|
|
|
|
- name: install libvirt packages
|
|
|
|
apt:
|
|
|
|
name:
|
|
|
|
- libvirt-daemon-system
|
|
|
|
- qemu-kvm
|
|
|
|
- qemu-utils
|
|
|
|
- qemu-block-extra
|
|
|
|
- vhostmd
|
|
|
|
- ceph-common
|
2023-09-01 15:42:25 -04:00
|
|
|
- libguestfs-tools
|
2023-10-11 13:18:05 -04:00
|
|
|
state: present
|
2023-09-01 15:42:30 -04:00
|
|
|
register: apt_res
|
|
|
|
retries: 5
|
|
|
|
until: apt_res is success
|
2023-09-01 15:42:19 -04:00
|
|
|
|
2023-12-27 13:57:21 -05:00
|
|
|
- name: install Prometheus libvirt exporter if enabled (Debian 11+)
|
2023-12-10 01:42:09 -05:00
|
|
|
apt:
|
|
|
|
name:
|
|
|
|
- prometheus-libvirt-exporter
|
|
|
|
register: apt_res
|
|
|
|
retries: 5
|
|
|
|
until: apt_res is success
|
2023-12-27 13:57:21 -05:00
|
|
|
when: enable_prometheus_exporters is defined and enable_prometheus_exporters and debian_version|int >= 11
|
2023-12-10 01:42:09 -05:00
|
|
|
|
2023-09-01 15:42:20 -04:00
|
|
|
- name: add libvirt user to ceph group
|
|
|
|
user:
|
|
|
|
name: libvirt-qemu
|
|
|
|
groups: ceph
|
|
|
|
append: yes
|
|
|
|
|
2023-09-01 15:42:28 -04:00
|
|
|
- name: add admin users to libvirt groups
|
|
|
|
user:
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
groups: kvm,libvirt
|
|
|
|
append: yes
|
|
|
|
with_items: "{{ admin_users }}"
|
|
|
|
|
2023-09-01 15:42:28 -04:00
|
|
|
- name: install libvirt configurations
|
2023-09-01 15:42:19 -04:00
|
|
|
template:
|
|
|
|
src: libvirt/{{ item }}.j2
|
|
|
|
dest: /etc/libvirt/{{ item }}
|
|
|
|
with_items:
|
|
|
|
- libvirtd.conf
|
|
|
|
- ceph-secret.xml
|
|
|
|
notify: restart libvirtd
|
|
|
|
|
2023-09-01 15:42:19 -04:00
|
|
|
- include: libvirt/bootstrap.yml
|
2023-09-01 15:42:29 -04:00
|
|
|
when: do_bootstrap is defined and do_bootstrap
|
2023-09-01 15:42:19 -04:00
|
|
|
run_once: yes
|
|
|
|
|
2023-09-01 15:42:19 -04:00
|
|
|
- name: get ceph libvirt secret key
|
|
|
|
command: ceph auth get-key client.libvirt
|
|
|
|
register: libvirt_key
|
|
|
|
|
2023-09-01 15:42:19 -04:00
|
|
|
- name: define ceph secret
|
|
|
|
command: virsh secret-define /etc/libvirt/ceph-secret.xml
|
|
|
|
ignore_errors: true
|
|
|
|
|
2023-09-01 15:42:19 -04:00
|
|
|
- name: set ceph libvirt secret value
|
2023-09-01 15:42:19 -04:00
|
|
|
command: virsh secret-set-value --secret {{ pvc_ceph_storage_secret_uuid }} --base64 {{ libvirt_key.stdout }}
|
2023-09-01 15:42:19 -04:00
|
|
|
ignore_errors: true
|
|
|
|
|
|
|
|
- name: configure libvirt for listening
|
2023-09-01 15:42:28 -04:00
|
|
|
template:
|
|
|
|
src: libvirt/libvirtd.default.j2
|
2023-09-01 15:42:19 -04:00
|
|
|
dest: /etc/default/libvirtd
|
|
|
|
notify: restart libvirtd
|
|
|
|
|
2023-09-01 15:42:26 -04:00
|
|
|
- name: install systemd unit file (override default on Bullseye)
|
|
|
|
template:
|
|
|
|
src: libvirt/libvirtd.service.j2
|
|
|
|
dest: /etc/systemd/system/libvirtd.service
|
|
|
|
register: systemd
|
2023-09-01 15:42:26 -04:00
|
|
|
notify: restart libvirtd
|
2023-09-01 15:42:26 -04:00
|
|
|
|
|
|
|
- name: reload systemd to apply changes
|
|
|
|
command: systemctl daemon-reload
|
|
|
|
when: systemd.changed
|
|
|
|
|
2023-09-01 15:42:28 -04:00
|
|
|
- name: create unit override configuration directory
|
|
|
|
file:
|
|
|
|
dest: /etc/systemd/system/libvirtd.service.d
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: install libvirt cgroup delegation configuration
|
|
|
|
template:
|
|
|
|
src: libvirt/{{ item }}.j2
|
|
|
|
dest: /etc/systemd/system/libvirtd.service.d/{{ item }}
|
|
|
|
with_items:
|
|
|
|
- cgroup-delegation.conf
|
|
|
|
register: systemd
|
|
|
|
notify: restart libvirtd
|
|
|
|
|
|
|
|
- name: reload systemd to apply changes
|
|
|
|
command: systemctl daemon-reload
|
|
|
|
when: systemd.changed
|
|
|
|
|
2023-09-01 15:42:26 -04:00
|
|
|
- name: start and enable services (not managed by PVC)
|
2023-09-01 15:42:22 -04:00
|
|
|
service:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: started
|
2023-09-01 15:42:26 -04:00
|
|
|
enabled: yes
|
2023-09-01 15:42:30 -04:00
|
|
|
ignore_errors: yes
|
2023-09-01 15:42:22 -04:00
|
|
|
with_items:
|
|
|
|
- vhostmd
|
|
|
|
|
2023-09-01 15:42:26 -04:00
|
|
|
- name: start but disable services (managed by PVC)
|
2023-09-01 15:42:19 -04:00
|
|
|
service:
|
|
|
|
name: "{{ item }}"
|
2023-09-01 15:42:26 -04:00
|
|
|
state: started
|
2023-09-01 15:42:19 -04:00
|
|
|
enabled: no
|
|
|
|
with_items:
|
|
|
|
- libvirtd
|
2023-09-01 15:42:19 -04:00
|
|
|
|
2023-11-03 12:10:19 -04:00
|
|
|
- name: disable socket services
|
|
|
|
service:
|
|
|
|
name: "{{ item }}"
|
|
|
|
enabled: no
|
|
|
|
with_items:
|
|
|
|
- libvirtd.socket
|
|
|
|
- libvirtd-ro.socket
|
|
|
|
- libvirtd-admin.socket
|
2023-12-27 15:35:17 -05:00
|
|
|
ignore_errors: yes
|
2023-11-03 12:10:19 -04:00
|
|
|
|
2023-09-01 15:42:19 -04:00
|
|
|
- meta: flush_handlers
|