summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2020-05-23 05:40:09 +0200
committerChristian Pointner <equinox@spreadspace.org>2020-05-25 00:04:27 +0200
commit7783703ff07eb90fea5a1251032dc2901602219d (patch)
treeb92e4a7cf4cde4f3e773fd2e1dd41ebd4d968ac8
parentadd role zfs sanoid (diff)
major revamp for zfs based vm images
-rw-r--r--inventory/host_vars/sk-tomnext-nc.yml36
-rw-r--r--inventory/host_vars/sk-tomnext.yml43
-rw-r--r--inventory/hosts.ini5
-rw-r--r--roles/vm/define/templates/libvirt-domain.xml.j24
-rw-r--r--roles/vm/host/tasks/main.yml6
-rw-r--r--roles/vm/host/tasks/zfs.yml12
-rw-r--r--roles/vm/install/tasks/main.yml23
7 files changed, 98 insertions, 31 deletions
diff --git a/inventory/host_vars/sk-tomnext-nc.yml b/inventory/host_vars/sk-tomnext-nc.yml
new file mode 100644
index 00000000..a302a298
--- /dev/null
+++ b/inventory/host_vars/sk-tomnext-nc.yml
@@ -0,0 +1,36 @@
+---
+vm_host: sk-tomnext
+
+install:
+ host: "{{ vm_host }}"
+ mem: 16384
+ numcpu: 8
+ disks:
+ primary: /dev/sda
+ scsi:
+ sda:
+ type: zfs
+ name: root
+ size: 50g
+ sdb:
+ type: zfs
+ name: data
+ size: 20g
+ interfaces:
+ - bridge: br-public
+ name: primary0
+ autostart: False
+
+network:
+ nameservers: "{{ hostvars[vm_host].vm_host.network.dns }}"
+ domain: "{{ host_domain }}"
+ systemd_link:
+ interfaces: "{{ install.interfaces }}"
+ primary:
+ interface: primary0
+ ip: "{{ hostvars[vm_host].vm_host.network.bridges.public.prefix | ipaddr(hostvars[vm_host].vm_host.network.bridges.public.offsets[inventory_hostname]) | ipaddr('address') }}"
+ mask: "{{ hostvars[vm_host].vm_host.network.bridges.public.prefix | ipaddr('netmask') }}"
+ gateway: "{{ hostvars[vm_host].vm_host.network.bridges.public.prefix | ipaddr('address') }}"
+ overlay: "{{ (hostvars[vm_host].vm_host.network.bridges.public.overlay.prefix | ipaddr(hostvars[vm_host].vm_host.network.bridges.public.overlay.offsets[inventory_hostname])).split('/')[0] }}"
+
+external_ip: "{{ network.primary.overlay }}"
diff --git a/inventory/host_vars/sk-tomnext.yml b/inventory/host_vars/sk-tomnext.yml
index d570f1b2..57f3dcf1 100644
--- a/inventory/host_vars/sk-tomnext.yml
+++ b/inventory/host_vars/sk-tomnext.yml
@@ -11,25 +11,6 @@ network: {}
base_intel_nic_stability_fix: true
-vm_host:
- network:
- dns:
- - 213.133.100.100
- - 213.133.98.98
- - 213.133.99.99
- bridges:
- public:
- prefix: 192.168.250.254/24
- offsets:
- sk-tomnext-nc: 103
- sk-tomnext-hp: 104
- nat: yes
- overlay:
- prefix: 94.130.206.64/26
- offsets:
- sk-tomnext-nc: 39
- sk-tomnext-hp: 40
-
ssh_keys_root: "{{ ssh_keys.equinox[env_group] + ssh_keys.dan }}"
apt_repo_components:
@@ -65,3 +46,27 @@ zfs_sanoid_modules:
use_template: production
recursive: yes
process_children_only: yes
+
+
+vm_host:
+ network:
+ dns:
+ - 213.133.100.100
+ - 213.133.98.98
+ - 213.133.99.99
+ bridges:
+ public:
+ prefix: 192.168.250.254/24
+ offsets:
+ sk-tomnext-nc: 103
+ sk-tomnext-hp: 104
+ nat: yes
+ overlay:
+ prefix: 94.130.206.64/26
+ offsets:
+ sk-tomnext-nc: 39
+ sk-tomnext-hp: 40
+ zfs:
+ default:
+ pool: storage
+ name: vm
diff --git a/inventory/hosts.ini b/inventory/hosts.ini
index 6f7d7a72..02d900e2 100644
--- a/inventory/hosts.ini
+++ b/inventory/hosts.ini
@@ -129,6 +129,8 @@ sk-2019 host_name=2019
sk-cloudia host_name=cloudia
sk-2019vm host_name=2019vm
sk-tomnext host_name=tomnext
+sk-tomnext-nc host_name=tomnext-nc
+sk-tomnext-hp
sk-testvm host_name=testvm
sk-torrent host_name=torrent
@@ -250,7 +252,8 @@ sk-torrent
ch-mimas
ele-gwhetzner
ele-mur
-
+sk-tomnext-nc
+sk-tomnext-hp
[hroot]
sk-2019
diff --git a/roles/vm/define/templates/libvirt-domain.xml.j2 b/roles/vm/define/templates/libvirt-domain.xml.j2
index 3465cec0..12c4f624 100644
--- a/roles/vm/define/templates/libvirt-domain.xml.j2
+++ b/roles/vm/define/templates/libvirt-domain.xml.j2
@@ -57,7 +57,7 @@
{% if src.type == 'lvm' %}
<source dev='/dev/mapper/{{ src.vg | replace('-', '--') }}-{{ src.lv | replace('-', '--') }}'/>
{% elif src.type == 'zfs' %}
- <source dev='/dev/zvol/{{ src.pool }}/{{ src.name }}'/>
+ <source dev='/dev/zvol/{{ vm_host.zfs[src.backend | default('default')].pool }}/{{ vm_host.zfs[src.backend | default('default')].name }}/{{ install_hostname }}/{{ src.name }}'/>
{% endif %}
<target dev='{{ device }}' bus='virtio'/>
</disk>
@@ -72,7 +72,7 @@
{% if src.type == 'lvm' %}
<source dev='/dev/mapper/{{ src.vg | replace('-', '--') }}-{{ src.lv | replace('-', '--') }}'/>
{% elif src.type == 'zfs' %}
- <source dev='/dev/zvol/{{ src.pool }}/{{ src.name }}'/>
+ <source dev='/dev/zvol/{{ vm_host.zfs[src.backend | default('default')].pool }}/{{ vm_host.zfs[src.backend | default('default')].name }}/{{ install_hostname }}/{{ src.name }}'/>
{% endif %}
<target dev='{{ device }}' bus='scsi'/>
</disk>
diff --git a/roles/vm/host/tasks/main.yml b/roles/vm/host/tasks/main.yml
index 0e11da3d..390016a2 100644
--- a/roles/vm/host/tasks/main.yml
+++ b/roles/vm/host/tasks/main.yml
@@ -19,9 +19,13 @@
notify: restart haveged
- name: install vm-host network
- when: vm_host.network is defined
+ when: "'network' in vm_host"
include_tasks: network.yml
+- name: prepare zfs volumes
+ when: "'zfs' in vm_host"
+ include_tasks: zfs.yml
+
- name: create lvm-based disk for installers
when: installer_lvm is defined
block:
diff --git a/roles/vm/host/tasks/zfs.yml b/roles/vm/host/tasks/zfs.yml
new file mode 100644
index 00000000..00de48a9
--- /dev/null
+++ b/roles/vm/host/tasks/zfs.yml
@@ -0,0 +1,12 @@
+---
+- name: create zfs base datasets
+ loop: "{{ lookup('dict', vm_host.zfs, wantlist=True) }}"
+ loop_control:
+ label: "{{ item.key }} -> {{ item.value.pool }}/{{ item.value.name }}{% if 'quota' in item.value %}={{ item.value.quota }}{% endif %}"
+ zfs:
+ name: "{{ item.value.pool }}/{{ item.value.name }}"
+ state: present
+ extra_zfs_properties:
+ quota: "{{ item.value.quota | default(omit) }}"
+ canmount: no
+ mountpoint: none
diff --git a/roles/vm/install/tasks/main.yml b/roles/vm/install/tasks/main.yml
index 50772e53..4fa673c5 100644
--- a/roles/vm/install/tasks/main.yml
+++ b/roles/vm/install/tasks/main.yml
@@ -1,22 +1,29 @@
---
- name: create lvm-based disks for vm
- loop: "{{ hostvars[install_hostname].install_cooked.disks.virtio | default({}) | combine(hostvars[install_hostname].install_cooked.disks.scsi | default({})) | dict2items }}"
+ loop: "{{ hostvars[install_hostname].install_cooked.disks.virtio | default({}) | combine(hostvars[install_hostname].install_cooked.disks.scsi | default({})) | dict2items | selectattr('value.type', 'eq', 'lvm') | list }}"
loop_control:
- label: "{% if item.value.type == 'lvm' %}{{ item.value.vg }} / {{ item.value.lv }} ({{ item.value.size }}){% else %}unused{% endif %}"
- when: item.value.type == 'lvm'
+ label: "{{ item.value.vg }} / {{ item.value.lv }} ({{ item.value.size }})"
lvol:
vg: "{{ item.value.vg }}"
lv: "{{ item.value.lv }}"
size: "{{ item.value.size }}"
state: present
-- name: create zfs-based disks for vm
- loop: "{{ hostvars[install_hostname].install_cooked.disks.virtio | default({}) | combine(hostvars[install_hostname].install_cooked.disks.scsi | default({})) | dict2items }}"
+- name: create zfs base datasets for vm
+ loop: "{{ hostvars[install_hostname].install_cooked.disks.virtio | default({}) | combine(hostvars[install_hostname].install_cooked.disks.scsi | default({})) | dict2items | selectattr('value.type', 'eq', 'zfs') | map(attribute='value.backend') | map('default', 'default') | unique | list }}"
+ zfs:
+ name: "{{ vm_host.zfs[item].pool }}/{{ vm_host.zfs[item].name }}/{{ install_hostname }}"
+ state: present
+ extra_zfs_properties:
+ canmount: no
+ mountpoint: none
+
+- name: create zfs-based disk volumes for vm
+ loop: "{{ hostvars[install_hostname].install_cooked.disks.virtio | default({}) | combine(hostvars[install_hostname].install_cooked.disks.scsi | default({})) | dict2items | selectattr('value.type', 'eq', 'zfs') | list }}"
loop_control:
- label: "{% if item.value.type == 'zfs' %}{{ item.value.pool }} / {{ item.value.name }} ({{ item.value.size }}){% else %}unused{% endif %}"
- when: item.value.type == 'zfs'
+ label: "{{ item.value.name }} on backend {{ item.value.backend | default('default') }} ({{ item.value.size }})"
zfs:
- name: "{{ item.value.pool }}/{{ item.value.name }}"
+ name: "{{ vm_host.zfs[item.value.backend | default('default')].pool }}/{{ vm_host.zfs[item.value.backend | default('default')].name }}/{{ install_hostname }}/{{ item.value.name }}"
state: present
extra_zfs_properties:
volsize: "{{ item.value.size }}"