aboutsummaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
authorbinary <me@rgoncalves.se>2021-01-19 19:13:27 +0100
committerbinary <me@rgoncalves.se>2021-01-19 19:13:27 +0100
commit42650055c6066989bb2c0d38613c6028b6188e9d (patch)
treeae2caa7e252710385bde3e98f893f4555e0d5c78 /roles
parent3481e1e128ec5522ac49b48c43e8e8b1a676ba38 (diff)
downloadinfrastructure-42650055c6066989bb2c0d38613c6028b6188e9d.tar.gz
Refactor bhyve role for new network setup
Diffstat (limited to 'roles')
-rw-r--r--roles/bhyve/tasks/guest.yml4
-rw-r--r--roles/bhyve/tasks/main.yml42
-rw-r--r--roles/bhyve/vars/main.yml1
3 files changed, 31 insertions, 16 deletions
diff --git a/roles/bhyve/tasks/guest.yml b/roles/bhyve/tasks/guest.yml
index 9cabf90..b24b434 100644
--- a/roles/bhyve/tasks/guest.yml
+++ b/roles/bhyve/tasks/guest.yml
@@ -4,11 +4,11 @@
---
-- name: check kvm directory
+- name: check vm directory
stat: path="/data/bhyve/{{ guest.name }}"
register: st
-- name: create all vm bound with current host
+- name: create all disks bound with current host
shell: vm create -s "{{ guest.disks[0].size }}" "{{ guest.name }}"
when: st.stat.isdir is not defined
diff --git a/roles/bhyve/tasks/main.yml b/roles/bhyve/tasks/main.yml
index 3ff902a..039ba10 100644
--- a/roles/bhyve/tasks/main.yml
+++ b/roles/bhyve/tasks/main.yml
@@ -1,6 +1,6 @@
# bhyve ~~ roles/bhyve/tasks/main.yml
-# bhyve hypervisor configuration
+# bhyve hypervisor configuration for FreeBSD based systems
---
@@ -25,8 +25,9 @@
mode: 0711
- name: load bhyve module
- shell: "! kldstat | grep vmm && kldload vmm"
- failed_when: false
+ shell: kldload vmm
+ register: result
+ failed_when: result.rc != 0 and "already loaded" not in result.stderr
- name: install bhyve components
package: name="{{ item }}"
@@ -36,10 +37,15 @@
- grub2-bhyve
- devcpu-data
+- name: retrieve all valid vms
+ set_fact: valid_vms="{% for vm in vms %}{{ vm.name }} {% endfor %}"
+
- name: enable bhyve vm
shell: |
sysrc vm_enable="YES"
- sysrc vm_dir="/data/bhyve"
+ sysrc vm_dir="{{ bhyve_dir }}"
+ sysrc vm_list="{{ valid_vms }}"
+ sysrc vm_delay="{{ bhyve_bootdelay }}"
- name: init vm directory and filesets
shell: vm init
@@ -49,19 +55,27 @@
vm switch create {{ hypervisor.switch }}
vm switch add public {{ hypervisor.interface }}
ignore_errors: true
+ register: result
+ failed_when: result.rc != 0 and "already exists" not in result.stderr and "failed to" not in result.stderr
- name: create per vm configuration
include: guest.yml guest="{{ item }}"
loop: "{{ vms }}"
-- name: activate on boot all enabled vm
- lineinfile:
- path: /etc/rc.conf
- regexp: "^vm_list="
- line: vm_list="{% for vm in vms %}{{ vm.name }} {% endfor %}"
+- name: retrieve all deprecated vms
+ find:
+ path: "{{ bhyve_dir }}"
+ file_type: directory
+ register: deprecated_vms
+
+- name: delete all deprecated vms
+ file:
+ path: "{{ item[1].path }}"
+ state: absent
+ when: (item[1].path | basename) not in "{{ valid_vms }}"
+ with_nested:
+ - "{{ vms }}"
+ - "{{ deprecated_vms.files }}"
-- name: set delay on boot between vm
- lineinfile:
- path: /etc/rc.conf
- regexp: "^vm_delay="
- line: vm_delay="5"
+- name: ensure all vms are started
+ shell: vm startall
diff --git a/roles/bhyve/vars/main.yml b/roles/bhyve/vars/main.yml
index 7819620..51813f5 100644
--- a/roles/bhyve/vars/main.yml
+++ b/roles/bhyve/vars/main.yml
@@ -7,6 +7,7 @@
bhyve_dir: "/data/bhyve"
bhyve_user: "bhyve"
bhyve_group: "bhyve"
+bhyve_bootdelay: "3"
bhyve_iso:
remember that computers suck.