From a344c92d8374d771b1d5aa8ab040e5c6c49ff783 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 1 Nov 2022 19:06:44 -0400 Subject: [PATCH] Configure bhyve. --- .../environments/laptop/host_vars/odofreebsd | 1 + ansible/roles/bhyve/defaults/main.yaml | 1 + ansible/roles/bhyve/files/arch.conf | 17 ++++++++++ ansible/roles/bhyve/tasks/freebsd.yaml | 31 +++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 ansible/roles/bhyve/files/arch.conf diff --git a/ansible/environments/laptop/host_vars/odofreebsd b/ansible/environments/laptop/host_vars/odofreebsd index 9c383e3..bb1a3c8 100644 --- a/ansible/environments/laptop/host_vars/odofreebsd +++ b/ansible/environments/laptop/host_vars/odofreebsd @@ -45,3 +45,4 @@ jail_list: conf: src: dagger bhyve_dataset: zroot/freebsd/release/vm +bhyve_list: [] diff --git a/ansible/roles/bhyve/defaults/main.yaml b/ansible/roles/bhyve/defaults/main.yaml index 1838e9c..d7cab58 100644 --- a/ansible/roles/bhyve/defaults/main.yaml +++ b/ansible/roles/bhyve/defaults/main.yaml @@ -1 +1,2 @@ bhyve_mountpoint: "/vm" +bhyve_list: [] diff --git a/ansible/roles/bhyve/files/arch.conf b/ansible/roles/bhyve/files/arch.conf new file mode 100644 index 0000000..1eec7e2 --- /dev/null +++ b/ansible/roles/bhyve/files/arch.conf @@ -0,0 +1,17 @@ +# Use UEFI when booting from a disk +loader="uefi" +graphics="yes" +xhci_mouse="yes" +graphics_listen="127.0.0.1" +#graphics_listen="10.216.1.1" +graphics_res="1920x1080" +#prestart="" + +cpu=1 +memory=1024M +network0_type="virtio-net" +network0_switch="customswitch" +disk0_type="virtio-blk" +disk0_name="disk0" +disk0_dev="sparse-zvol" +virt_random="yes" # virtio-rnd diff --git a/ansible/roles/bhyve/tasks/freebsd.yaml b/ansible/roles/bhyve/tasks/freebsd.yaml index bbdf85f..8f73216 100644 --- a/ansible/roles/bhyve/tasks/freebsd.yaml +++ b/ansible/roles/bhyve/tasks/freebsd.yaml @@ -20,3 +20,34 @@ state: present extra_zfs_properties: mountpoint: "{{ bhyve_mountpoint }}" + +- name: Enable bhyve + community.general.sysrc: + name: "{{ item.name }}" + value: "{{ item.value }}" + path: /etc/rc.conf.d/vm + loop: + - name: vm_enable + value: "YES" + - name: vm_dir + value: "zfs:{{ bhyve_dataset }}" + - name: vm_list + value: "{{ bhyve_list|community.general.json_query('[?enabled==`true`].name')|join(' ') }}" + - name: vm_delay + value: "5" + +- name: init vm-bhyve + command: vm init + args: + creates: "{{ bhyve_mountpoint }}/.templates" + +- name: Install Configuration + copy: + src: "files/{{ item.src }}" + dest: "{{ item.dest }}" + mode: 0644 + owner: root + group: wheel + loop: + - src: arch.conf + dest: "{{ bhyve_mountpoint }}/.templates/arch.conf"