Files
configpolicy/roles/vmhost/tasks/main.yml
Dustin C. Hatch 0cd58564c9 r/vmhost: Add autostart script
*libvirt*'s native autostart functionality does not work well for
machines that migrate between hosts.  Machines lose their auto-start
flag when they are migrated, and the flag is not restored if they are
migrated back.  This makes the feature pretty useless for us.

To work around this limitation, I've added a script that is run during
boot that will start the machines listed in `/etc/vm-autostart`, if they
exist.  That file can also insert a delay between starting two machines,
which may be useful to allow services to fully start on one machine
before starting another that may depend on them.
2022-08-20 21:15:31 -05:00

141 lines
3.2 KiB
YAML

- name: ensure required packages are installed
package:
name: '{{ vmhost_required_packages }}'
state: present
tags:
- install
- name: ensure libvirtd is configured
template:
src: libvirtd.conf.j2
dest: /etc/libvirt/libvirtd.conf
mode: '0644'
- name: ensure libvirt can use nfs
seboolean:
name: virt_use_nfs
state: true
persistent: true
- name: ensure libvirt runtime configuration directories exists
file:
path: /var/lib/libvirt/config/{{ item }}
mode: '0700'
state: directory
with_items:
- qemu
- storage
- name: ensure libvirt runtime directory bind mounts are set
mount:
path: /etc/libvirt/{{ item }}
src: /var/lib/libvirt/config/{{ item }}
fstype: none
opts: bind
state: mounted
with_items:
- qemu
- storage
- name: ensure libvirtd starts at boot
service:
name: libvirtd
enabled: true
- name: ensure libvirtd is running
service:
name: libvirtd
state: started
- name: ensure libvirt networks are defined
virt_net:
command: define
name: '{{ item.name }}'
xml: '{{ lookup("template", "net-" + item.type + ".xml.j2") }}'
with_items: '{{ libvirt_networks }}'
- name: ensure libvirt networks are active
virt_net:
name: '{{ item.name }}'
state: active
with_items: '{{ libvirt_networks }}'
- name: ensure libvirt networks start at boot
virt_net:
name: '{{ item.name }}'
autostart: true
with_items: '{{ libvirt_networks }}'
- name: ensure libvirtd migration port is allowed in the firewall
firewalld:
port: 49152/tcp
permanent: false
immediate: true
state: enabled
notify: save firewalld configuration
- name: ensure systemd ksm unit is installed
copy:
src: ksm.service
dest: /etc/systemd/system/ksm.service
mode: '0644'
notify: reload systemd
- name: ensure systemd ksm unit starts at boot
service:
name: ksm
enabled: true
- name: ensure systemd ksm unit is running
service:
name: ksm
state: started
- name: ensure required mount helper utilities are installed
package:
name: '{{ shared_volume_mount_packages }}'
state: present
tags: install
- name: ensure storage volumes are mounted
mount:
path: '{{ item.mountpoint }}'
src: '{{ item.host }}:{{ item.share }}'
fstype: '{{ item.fstype|d("nfs") }}'
opts: '{{ item.opts|d(omit) }}'
state: mounted
with_items: '{{ mount_shared_volumes }}'
tags: mount
- name: ensure vm-autostart script is installed
copy:
src: vm-autostart.sh
dest: /usr/local/libexec/vm-autostart.sh
mode: u=rwx,go=rx
owner: root
group: root
tags:
- install
- vm-autostart
- name: ensure vm-autostart is configured
template:
src: vm-autostart.j2
dest: /etc/vm-autostart
mode: u=rw,go=r
owner: root
group: root
tags:
- vm-autostart
- name: ensure vm-autostart.service unit file is installed
copy:
src: vm-autostart.service
dest: /etc/systemd/system/vm-autostart.service
mode: u=rw,go=r
owner: root
group: root
notify:
- reload systemd
tags:
- vm-autostart
- systemd
- name: ensure vm-autostart.service is enabled
service:
name: vm-autostart
enabled: true
tags:
- service