aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbinary <me@rgoncalves.se>2020-11-19 23:40:34 +0100
committerbinary <me@rgoncalves.se>2020-11-19 23:40:34 +0100
commit3e891b1a1fe21c26e7a09293106bf60dea6334e5 (patch)
treea29d9e192423a39f9e6720a6acdaa05a24b0676f
parentc7cca6eb560146116a57fb2a2bfff35c9ba023bc (diff)
downloadinfrastructure-3e891b1a1fe21c26e7a09293106bf60dea6334e5.tar.gz
Basic behyve initialization
-rw-r--r--roles/bhyve/tasks/guest.yml23
-rw-r--r--roles/bhyve/tasks/main.yml67
-rw-r--r--roles/bhyve/templates/alpine.conf.j214
-rw-r--r--roles/bhyve/templates/openbsd.conf.j214
-rw-r--r--roles/bhyve/vars/main.yml24
-rw-r--r--roles/minecraft/tasks/main.yml27
6 files changed, 149 insertions, 20 deletions
diff --git a/roles/bhyve/tasks/guest.yml b/roles/bhyve/tasks/guest.yml
new file mode 100644
index 0000000..9cabf90
--- /dev/null
+++ b/roles/bhyve/tasks/guest.yml
@@ -0,0 +1,23 @@
+
+# bhyve guests ~~ roles/bhyve/tasks/guest.yml
+# bhyve guest configuration
+
+---
+
+- name: check kvm directory
+ stat: path="/data/bhyve/{{ guest.name }}"
+ register: st
+
+- name: create all vm bound with current host
+ shell: vm create -s "{{ guest.disks[0].size }}" "{{ guest.name }}"
+ when: st.stat.isdir is not defined
+
+- name: create guest configuration
+ template:
+ src: "templates/{{ guest.image }}.conf.j2"
+ dest: "/data/bhyve/{{ guest.name }}/{{ guest.name }}.conf"
+ vars:
+ guest_cpu: "{{ guest.cpu }}"
+ guest_memory: "{{ guest.memory }}"
+ guest_switch: "{{ hypervisor.switch }}"
+ guest_disks: "{{ guest.disks }}"
diff --git a/roles/bhyve/tasks/main.yml b/roles/bhyve/tasks/main.yml
new file mode 100644
index 0000000..34cafd8
--- /dev/null
+++ b/roles/bhyve/tasks/main.yml
@@ -0,0 +1,67 @@
+
+# bhyve ~~ roles/bhyve/tasks/main.yml
+# bhyve hypervisor configuration
+
+---
+
+- name: create bhyve group
+ group:
+ name: bhyve
+ state: present
+
+- name: create bhyve user
+ user:
+ name: bhyve
+ group: bhyve
+ comment: Unpreviliged user for bhyve guests
+ shell: /sbin/nologin
+ 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: "! kldstat | grep vmm && kldload vmm"
+ failed_when: false
+
+- name: install bhyve components
+ package: name="{{ item }}"
+ loop:
+ - vm-bhyve
+ - bhyve-firmware
+ - grub2-bhyve
+
+- name: enable bhyve vm
+ shell: |
+ sysrc vm_enable="YES"
+ sysrc vm_dir="/data/bhyve"
+
+- 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
+
+- 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: set delay on boot between vm
+ lineinfile:
+ path: /etc/rc.conf
+ regexp: "^vm_delay="
+ line: vm_delay="5"
diff --git a/roles/bhyve/templates/alpine.conf.j2 b/roles/bhyve/templates/alpine.conf.j2
new file mode 100644
index 0000000..58cad66
--- /dev/null
+++ b/roles/bhyve/templates/alpine.conf.j2
@@ -0,0 +1,14 @@
+loader="grub"
+cpu={{ guest_cpu }}
+memory={{ guest_memory }}
+
+network0_type="virtio-net"
+network0_switch="{{ guest_switch }}"
+
+disk0_type="virtio-blk"
+disk0_name="disk0.img"
+
+grub_install0="linux /boot/vmlinuz-lts initrd=/boot/initramfs-lts alpine_dev=cdrom:iso9660 modules=loop,squashfs,sd-mod,usb-storage,sr-mod"
+grub_install1="initrd /boot/initramfs-lts"
+grub_run0="linux /boot/vmlinuz-lts root=/dev/vda3 modules=ext4"
+grub_run1="initrd /boot/initramfs-lts"
diff --git a/roles/bhyve/templates/openbsd.conf.j2 b/roles/bhyve/templates/openbsd.conf.j2
new file mode 100644
index 0000000..c791c6c
--- /dev/null
+++ b/roles/bhyve/templates/openbsd.conf.j2
@@ -0,0 +1,14 @@
+loader="grub"
+cpu={{ guest_cpu }}
+memory={{ guest_memory }}
+
+network0_type="virtio-net"
+network0_switch="{{ guest_switch }}"
+
+disk0_type="virtio-blk"
+disk0_name="disk0.img"
+
+grub_install0="kopenbsd -h com0 /6.8/amd64/bsd.rd"
+grub_run0="kopenbsd -h com0 -r sd0a /bsd"
+
+bhyve_options="-w"
diff --git a/roles/bhyve/vars/main.yml b/roles/bhyve/vars/main.yml
new file mode 100644
index 0000000..7819620
--- /dev/null
+++ b/roles/bhyve/vars/main.yml
@@ -0,0 +1,24 @@
+
+# bhyve ~~ roles/bhyve/vars/main.yml
+# main variables for all bhyve tasks
+
+---
+
+bhyve_dir: "/data/bhyve"
+bhyve_user: "bhyve"
+bhyve_group: "bhyve"
+
+bhyve_iso:
+
+ - name: "alpine"
+ version: "3.12.1"
+ versiondir: "3.12"
+ url: "http://dl-cdn.alpinelinux.org/alpine/vVERSIONDIR/releases/x86_64/alpine-virt-VERSION-x86_64.iso"
+ sha256: "http://dl-cdn.alpinelinux.org/alpine/vVERSIONDIR/releases/x86_64/alpine-virt-VERSION-x86_64.iso.sha256"
+
+ - name: "openbsd"
+ version: "68"
+ versiondir: "6.8"
+ url: "https://cdn.openbsd.org/pub/OpenBSD/VERSIONDIR/amd64/installVERSION.img"
+ sha256: "d3603291fa50bcf056fa304acf9311556331598f31dfbbbc6797ae88f43c948b"
+
diff --git a/roles/minecraft/tasks/main.yml b/roles/minecraft/tasks/main.yml
index 56a9eed..bbb6202 100644
--- a/roles/minecraft/tasks/main.yml
+++ b/roles/minecraft/tasks/main.yml
@@ -3,39 +3,26 @@
---
-- name: Check java installation
- package:
- name: openjdk11-jre
- state: present
-
-- name: Create minecraft user
+- name: create minecraft user
user:
name: "{{ minecraft_user }}"
group: "{{ minecraft_user }}"
-- name: Create minecraft directory
+- name: create minecraft directory
file:
path: "{{ minecraft_dir }}"
owner: "{{ minecraft_user }}"
group: "{{ minecraft_user }}"
state: directory
-- name: Download minecraft server
+- name: download minecraft server
get_url:
url: "{{ minecraft_url }}"
dest: "{{ minecraft_dir }}/{{ minecraft_bin }}"
owner: "{{ minecraft_user }}"
-- name: Enable eula
+- name: enable eula
+ shell: echo "eula=true" >> eula.txt
+ chdir: "{{ minecraft_dir }}"
+ become: true
become_user: "{{ minecraft_user }}"
- shell: echo "eula=true" >> {{ minecraft_dir}}/eula.txt
-
-- name: Create rc script
- include_role:
- name: rc
- vars:
- rc_name: "minecraft"
- rc_cmd: "/usr/bin/java"
- rc_args: "-jar {{ minecraft_dir }}/{{ minecraft_bin }}"
- rc_user: "{{ minecraft_user }}"
-
remember that computers suck.