From 56aa88c7e272ccfd645695103d5bca653005aad4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Tue, 7 Dec 2021 21:42:58 +0000 Subject: roles/vmm: Use host kernels for openbsd guests --- group_vars/all.yml | 3 +- roles/vmm/defaults/main.yml | 6 +--- roles/vmm/tasks/autoinstall-configuration.yml | 27 ---------------- roles/vmm/tasks/autoinstall_configuration.yml | 45 +++++++++++++++++++++++++++ roles/vmm/tasks/facts.yml | 8 ++--- roles/vmm/tasks/main.yml | 2 +- roles/vmm/templates/autoinstall.conf.j2 | 10 ++++-- roles/vmm/templates/vm.conf.j2 | 3 ++ 8 files changed, 63 insertions(+), 41 deletions(-) delete mode 100644 roles/vmm/tasks/autoinstall-configuration.yml create mode 100644 roles/vmm/tasks/autoinstall_configuration.yml diff --git a/group_vars/all.yml b/group_vars/all.yml index ea024a7..12290cb 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -2,6 +2,7 @@ ansible_hostname: "{{ ansible_host }}" ansible_become_method: su __is_vm: false +__domain_name: "{{ inventory_hostname }}.sushi.{{ __global_name }}" __ip: external: @@ -11,6 +12,6 @@ __services: {} __global_domain_controller: dc0 __global_domain_name: rgoncalves.se -__global_dns: +__global_domain_name_servers: - 8.8.8.8 - 1.1.1.1 diff --git a/roles/vmm/defaults/main.yml b/roles/vmm/defaults/main.yml index 8d26a49..13e8b92 100644 --- a/roles/vmm/defaults/main.yml +++ b/roles/vmm/defaults/main.yml @@ -9,6 +9,7 @@ vmm_default_timezone: Europe/Stockholm vmm_default_fallback_http: true vmm_default_ssh_key: a +vmm_image_openbsd_kernel_prefix: /bsd.vm vmm_network_forwarded_ips: ["", 6] @@ -22,11 +23,6 @@ vmm_iso: url: https://dl-cdn.alpinelinux.org/alpine/v3.15/releases/x86_64/alpine-virt-3.15.0-x86_64.iso checksum: sha256:e97eaedb3bff39a081d1d7e67629d5c0e8fb39677d6a9dd1eaf2752e39061e02 - - name: openbsd - version: 6.8 - url: https://cdn.openbsd.org/pub/OpenBSD/7.0/amd64/install70.img - checksum: sha256:6bc7f945c2709247d449892c33c0f1b9a31590528572c1e988fef4a7637210e6 - # vmm_vms: # - name: # image: diff --git a/roles/vmm/tasks/autoinstall-configuration.yml b/roles/vmm/tasks/autoinstall-configuration.yml deleted file mode 100644 index e05b11c..0000000 --- a/roles/vmm/tasks/autoinstall-configuration.yml +++ /dev/null @@ -1,27 +0,0 @@ -- name: include httpd role variables - include_vars: "{{ inventory_dir }}/roles/httpd/defaults/main.yml" - -- name: create autoinstall directory - file: - path: /var/www/htdocs/autoinstall - owner: www - group: www - mode: 0700 - state: directory - -- name: generate autoinstall files - template: - src: autoinstall.conf.j2 - dest: "/var/www/htdocs/autoinstall/{{ item.lladdr }}-install.conf" - owner: www - group: www - mode: 0640 - loop: "{{ vmm_vms }}" - -- name: generate httpd configuration - template: - src: httpd.conf.j2 - dest: "{{ httpd_configuration_dir }}/autoinstall.conf" - owner: 0 - group: 0 - mode: 0640 diff --git a/roles/vmm/tasks/autoinstall_configuration.yml b/roles/vmm/tasks/autoinstall_configuration.yml new file mode 100644 index 0000000..cd52a84 --- /dev/null +++ b/roles/vmm/tasks/autoinstall_configuration.yml @@ -0,0 +1,45 @@ +- name: include httpd role variables + include_vars: "{{ inventory_dir }}/roles/httpd/defaults/main.yml" + +- name: create autoinstall directory + file: + path: /var/www/htdocs/autoinstall + owner: www + group: www + mode: 0700 + state: directory + +- name: generate autoinstall files + template: &generation_steps + src: autoinstall.conf.j2 + dest: "/var/www/htdocs/autoinstall/{{ item.lladdr }}-install.conf" + owner: www + group: www + mode: 0640 + when: item.image == "openbsd" + loop: "{{ vmm_vms }}" + +- name: generate autoupgrade files + template: + <<: *generation_steps + dest: "/var/www/htdocs/autoinstall/{{ item.lladdr }}-upgrade.conf" + when: item.image == "openbsd" + loop: "{{ vmm_vms }}" + +- name: generate httpd configuration + template: + <<: *generation_steps + src: httpd.conf.j2 + dest: "{{ httpd_configuration_dir }}/autoinstall.conf" + owner: 0 + group: 0 + +- name: link openbsd vm kernel to host kernel + file: + src: /bsd.sp + dest: "{{ vmm_image_openbsd_kernel_prefix }}.{{ item.name }}" + owner: 0 + group: 0 + state: hard + when: item.image == "openbsd" + loop: "{{ vmm_vms }}" diff --git a/roles/vmm/tasks/facts.yml b/roles/vmm/tasks/facts.yml index c7b453b..58a6df5 100644 --- a/roles/vmm/tasks/facts.yml +++ b/roles/vmm/tasks/facts.yml @@ -2,10 +2,10 @@ set_fact: vmm_vms_tmp: > {{ vmm_vms_tmp | default([]) + [ item | combine({ - 'lladdr': item.name - | hash('sha1') - | truncate(12, True, '') - | ansible.netcommon.hwaddr('unix') + "lladdr": item.name + | hash("sha1") + | truncate(12, True, "") + | ansible.netcommon.hwaddr("unix") }) ] }} loop: "{{ vmm_vms }}" diff --git a/roles/vmm/tasks/main.yml b/roles/vmm/tasks/main.yml index c596664..26580f2 100644 --- a/roles/vmm/tasks/main.yml +++ b/roles/vmm/tasks/main.yml @@ -14,7 +14,7 @@ include_tasks: facts.yml - name: include autoinstall generation - include_tasks: autoinstall-configuration.yml + include_tasks: autoinstall_configuration.yml tags: task_autoinstall_configuration - name: include iso management diff --git a/roles/vmm/templates/autoinstall.conf.j2 b/roles/vmm/templates/autoinstall.conf.j2 index de64c42..829c90f 100644 --- a/roles/vmm/templates/autoinstall.conf.j2 +++ b/roles/vmm/templates/autoinstall.conf.j2 @@ -1,9 +1,13 @@ +{% set guest = hostvars[item.name] %} System hostname = {{ item.name }} +Network interfaces = vio0 +IPv4 address for vio0 = {{ host.__ip.external }} +Using DNS domainname = {{ host.__domain_name }} +Using DNS nameservers = {{ __global_domain_name_servers | join (" ") }} Password for root = {{ vmm_default_password }} -Network interfaces = run0 -IPv4 address for run0 = dhcp -Public ssh key for user = {{ vmm_default_ssh_key }} +Public ssh key for root account = {{ vmm_default_ssh_key }} Which disk is the root disk = sd0 +Allow root ssh login = yes What timezone are you in = {{ vmm_default_timezone }} Unable to connect using https. Use http instead = {{ "yes" if vmm_default_fallback_http else "no" }} Location of sets = http diff --git a/roles/vmm/templates/vm.conf.j2 b/roles/vmm/templates/vm.conf.j2 index 8653616..32e4316 100644 --- a/roles/vmm/templates/vm.conf.j2 +++ b/roles/vmm/templates/vm.conf.j2 @@ -10,6 +10,9 @@ switch "{{ vmm_network_switch.name }}" { vm "{{ vm.name }}" { {% if vm.enabled is defined and not vm.enabled %} disable +{% endif %} +{% if vm.image == "openbsd" %} + boot "/bsd.vm.{{ vm.name }}" {% endif %} memory {{ vm.memory }} disk "{{ vmm_disk_dir }}/{{ vm.name }}.{{ vmm_disk_format }}" -- cgit v1.2.3