diff options
Diffstat (limited to 'roles/bhyve/tasks/main.yml')
-rw-r--r-- | roles/bhyve/tasks/main.yml | 42 |
1 files changed, 28 insertions, 14 deletions
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 |