blob: e39e5e778ed3511ed60dab61ac7dc75b2779f3b8 (
plain) (
tree)
|
|
# bhyve ~~ roles/bhyve/tasks/main.yml
# bhyve hypervisor configuration for FreeBSD based systems
---
- name: retrieve active vms
set_fact:
active_vms: "{{ vms | map(attribute='name') | join(' ') }}"
- name: create bhyve group
group:
name: bhyve
state: present
- name: create bhyve user
user:
name: "{{ bhyve_user }}"
group: "{{ bhyve_group }}"
comment: Unpreviliged user for bhyve guests
system: true
- name: check existence of bhyve directory
file:
path: "{{ bhyve_dir }}"
owner: "{{ bhyve_user }}"
group: "{{ bhyve_user }}"
state: directory
mode: 0711
- name: install bhyve dependencies
package:
name: "{{ bhyve_dependencies }}"
- name: load bhyve module
shell: kldload vmm
register: result
failed_when: result.rc != 0 and "already loaded" not in result.stderr
- name: init bhyve vm
shell: |
sysrc vm_enable="YES"
sysrc vm_dir="{{ bhyve_dir }}"
sysrc vm_list="{{ active_vms }}"
sysrc vm_delay="{{ bhyve_bootdelay }}"
vm init
- name: create network switch
shell: |
vm switch create {{ hypervisor.switch }}
vm switch add public {{ hypervisor.interface }}
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: retrieve all iso
get_url:
url: "{{ item }}"
dest: "{{ bhyve_dir }}/.iso"
loop: "{{ bhyve_iso }}"
- name: retrieve inactive vms
find:
path: "{{ bhyve_dir }}"
file_type: directory
register: result
- name: compute retrieved vms to list
set_fact:
result:
"{{ result.files | map(attribute='path') | map('basename') | list }}"
active_vms: "{{ active_vms.split(' ') }}"
- name: compute vms to be destroyed
set_fact:
inactive_vms: "{{ result | difference(active_vms) }}"
- name: show vms to be destroyed
debug:
msg: "{{ inactive_vms }}"
- name: delete all deprecated vms
file:
path: "{{ bhyve_dir }}/{{ item }}"
state: absent
when: bhyve_strict
loop: "{{ inactive_vms }}"
|