aboutsummaryrefslogblamecommitdiffstats
path: root/roles/bhyve/tasks/main.yml
blob: 1b41de045fe78f8e971636446db233ef4cf264bc (plain) (tree)
1
2
3
4
5
6
7
8
9

                                     
                                                          


   


                                                                     









                                               










                                          


                                                                       






                                
                 



                         


                                          








                                                   

                                                                                                            




                                       





                                
                               


                           
                      




                                 
                                                                   

                 
                              

# bhyve ~~ roles/bhyve/tasks/main.yml
# bhyve hypervisor configuration for FreeBSD based systems

---

- name: retrieve all valid vms
  set_fact: valid_vms="{% for vm in vms %}{{ vm.name }} {% endfor %}"

- name: create bhyve group
  group:
    name: bhyve
    state: present

- name: create bhyve user
  user:
    name: bhyve
    group: bhyve
    comment: Unpreviliged user for bhyve guests
    system: true

- name: check existence of bhyve directory
  file:
    path: /data/bhyve
    owner: bhyve
    group: bhyve
    state: directory
    mode: 0711

- name: load bhyve module
  shell: kldload vmm
  register: result
  failed_when: result.rc != 0 and "already loaded" not in result.stderr

- name: install bhyve components
  package: name="{{ item }}"
  loop:
    - vm-bhyve
    - bhyve-firmware
    - grub2-bhyve
    - devcpu-data

- name: enable bhyve vm
  shell: |
    sysrc vm_enable="YES"
    sysrc vm_dir="{{ bhyve_dir }}"
    sysrc vm_list="{{ valid_vms }}"
    sysrc vm_delay="{{ bhyve_bootdelay }}"

- name: init vm directory and filesets
  shell: vm init

- name: create network switch
  shell: |
    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: retrieve all iso
  get_url:
    url: "{{ item }}"
    dest: "{{ bhyve_dir }}/.iso"
  loop: "{{ bhyve_iso }}"

- name: retrieve all active vms
  find:
    path: "{{ bhyve_dir }}"
    file_type: directory
  register: active_vms

- name: delete all deprecated vms
  file:
    path: "{{ item[1].path }}"
    state: absent
  when: bhyve_strict and (item[1].path | basename) not in valid_vms
  with_nested:
    - "{{ vms }}"
    - "{{ active_vms.files }}"
remember that computers suck.