aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Gonçalves <me@rgoncalves.se>2021-12-07 15:41:02 +0000
committerRomain Gonçalves <me@rgoncalves.se>2021-12-07 20:24:51 +0000
commit9bd2c8c17a22c84da9a6ba6407c5b928d77fb469 (patch)
treee382576853ac2ebfeffcf3eda6e45f6ec9618656
parent12cf22b1a8d9ad23809ad8048119a6920cbb9675 (diff)
downloadrules-9bd2c8c17a22c84da9a6ba6407c5b928d77fb469.tar.gz
roles/vmm: Serve autoinstall configurations via httpd
-rw-r--r--host_vars/stack0.yml4
-rw-r--r--roles/vmm/defaults/main.yml12
-rw-r--r--roles/vmm/meta/main.yml3
-rw-r--r--roles/vmm/tasks/autoinstall-configuration.yml27
-rw-r--r--roles/vmm/tasks/disk.yml2
-rw-r--r--roles/vmm/tasks/facts.yml8
-rw-r--r--roles/vmm/tasks/main.yml34
-rw-r--r--roles/vmm/tasks/network.yml27
-rw-r--r--roles/vmm/templates/autoinstall.conf.j212
-rw-r--r--roles/vmm/templates/hostname.j21
-rw-r--r--roles/vmm/templates/httpd.conf.j24
-rw-r--r--roles/vmm/templates/vm.conf.j22
12 files changed, 100 insertions, 36 deletions
diff --git a/host_vars/stack0.yml b/host_vars/stack0.yml
index 5d0791c..ba88fc8 100644
--- a/host_vars/stack0.yml
+++ b/host_vars/stack0.yml
@@ -2,7 +2,7 @@ __ip:
external: 192.168.5.40
internal: 10.10.0.40
-__vms:
+vmm_vms:
- name: stack0-dc1
image: openbsd
memory: 4G
@@ -13,7 +13,7 @@ __vms:
memory: 4G
size: 8G
- - name: stack0-git0
+ - name: stack0-dev0
image: openbsd
memory: 2G
size: 8G
diff --git a/roles/vmm/defaults/main.yml b/roles/vmm/defaults/main.yml
index 1dcb012..8d26a49 100644
--- a/roles/vmm/defaults/main.yml
+++ b/roles/vmm/defaults/main.yml
@@ -4,6 +4,12 @@ vmm_disk_dir: /data/vmm/disk.d
vmm_disk_format: qcow2
vmm_configuration_file: /etc/vm.conf
+vmm_default_password: a
+vmm_default_timezone: Europe/Stockholm
+vmm_default_fallback_http: true
+vmm_default_ssh_key: a
+
+
vmm_network_forwarded_ips: ["", 6]
vmm_network_switch:
@@ -20,3 +26,9 @@ vmm_iso:
version: 6.8
url: https://cdn.openbsd.org/pub/OpenBSD/7.0/amd64/install70.img
checksum: sha256:6bc7f945c2709247d449892c33c0f1b9a31590528572c1e988fef4a7637210e6
+
+# vmm_vms:
+# - name:
+# image:
+# memory:
+# size:
diff --git a/roles/vmm/meta/main.yml b/roles/vmm/meta/main.yml
new file mode 100644
index 0000000..6b163d1
--- /dev/null
+++ b/roles/vmm/meta/main.yml
@@ -0,0 +1,3 @@
+dependencies:
+ - role: httpd_pre
+ tags: dependency
diff --git a/roles/vmm/tasks/autoinstall-configuration.yml b/roles/vmm/tasks/autoinstall-configuration.yml
new file mode 100644
index 0000000..e05b11c
--- /dev/null
+++ b/roles/vmm/tasks/autoinstall-configuration.yml
@@ -0,0 +1,27 @@
+- 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/disk.yml b/roles/vmm/tasks/disk.yml
index 24dd491..423d855 100644
--- a/roles/vmm/tasks/disk.yml
+++ b/roles/vmm/tasks/disk.yml
@@ -2,7 +2,7 @@
command:
cmd: vmctl create -s "{{ item.size }}" "{{ item.name }}.{{ vmm_disk_format }}"
chdir: "{{ vmm_disk_dir }}"
- loop: "{{ __vms }}"
+ loop: "{{ vmm_vms }}"
register: result
changed_when: result.rc == 0
failed_when:
diff --git a/roles/vmm/tasks/facts.yml b/roles/vmm/tasks/facts.yml
index 7cf4f0c..c7b453b 100644
--- a/roles/vmm/tasks/facts.yml
+++ b/roles/vmm/tasks/facts.yml
@@ -1,14 +1,14 @@
- name: generate lladdr variable for virtual machines
set_fact:
- tmp_vms: >
- {{ tmp_vms | default([]) + [ item | combine({
+ vmm_vms_tmp: >
+ {{ vmm_vms_tmp | default([]) + [ item | combine({
'lladdr': item.name
| hash('sha1')
| truncate(12, True, '')
| ansible.netcommon.hwaddr('unix')
}) ] }}
- loop: "{{ __vms }}"
+ loop: "{{ vmm_vms }}"
- name: save variables
set_fact:
- __vms: "{{ tmp_vms }}"
+ vmm_vms: "{{ vmm_vms_tmp }}"
diff --git a/roles/vmm/tasks/main.yml b/roles/vmm/tasks/main.yml
index 3c5a462..c596664 100644
--- a/roles/vmm/tasks/main.yml
+++ b/roles/vmm/tasks/main.yml
@@ -13,6 +13,10 @@
- name: include facts generation
include_tasks: facts.yml
+- name: include autoinstall generation
+ include_tasks: autoinstall-configuration.yml
+ tags: task_autoinstall_configuration
+
- name: include iso management
include_tasks: iso.yml
tags: task_iso
@@ -21,33 +25,9 @@
include_tasks: disk.yml
tags: task_disk
-- name: start ip forwarding
- command: sysctl net.inet.ip{{ item }}.forwarding=1
- loop: "{{ vmm_network_forwarded_ips }}"
-
-- name: enable ip forwarding
- lineinfile:
- path: /etc/sysctl.conf
- regexp: "^net.inet.ip{{ item }}.forwarding="
- line: "net.inet.ip{{ item }}.forwarding=1"
- owner: 0
- group: 0
- mode: 0640
- create: true
- loop: "{{ vmm_network_forwarded_ips }}"
-
-- name: create network switch
- lineinfile:
- path: "/etc/hostname.{{ vmm_network_switch.interface }}"
- regexp: &network_line "add {{ ansible_default_ipv4.interface }}"
- line: *network_line
- owner: 0
- group: 0
- mode: 0640
- create: true
-
-- name: start network switch
- command: "sh /etc/netstart {{ vmm_network_switch.interface }}"
+- name: include network management
+ include_tasks: network.yml
+ tags: task_network
- name: generate vmm configuration
template:
diff --git a/roles/vmm/tasks/network.yml b/roles/vmm/tasks/network.yml
new file mode 100644
index 0000000..b8fc7e1
--- /dev/null
+++ b/roles/vmm/tasks/network.yml
@@ -0,0 +1,27 @@
+- name: start ip forwarding
+ command: sysctl net.inet.ip{{ item }}.forwarding=1
+ loop: "{{ vmm_network_forwarded_ips }}"
+
+- name: enable ip forwarding
+ lineinfile:
+ path: /etc/sysctl.conf
+ regexp: "^net.inet.ip{{ item }}.forwarding="
+ line: "net.inet.ip{{ item }}.forwarding=1"
+ owner: 0
+ group: 0
+ mode: 0640
+ create: true
+ loop: "{{ vmm_network_forwarded_ips }}"
+
+- name: create network switch
+ lineinfile:
+ path: "/etc/hostname.{{ vmm_network_switch.interface }}"
+ regexp: &network_line "add {{ ansible_default_ipv4.interface }}"
+ line: *network_line
+ owner: 0
+ group: 0
+ mode: 0640
+ create: true
+
+- name: start network switch
+ command: "sh /etc/netstart {{ vmm_network_switch.interface }}"
diff --git a/roles/vmm/templates/autoinstall.conf.j2 b/roles/vmm/templates/autoinstall.conf.j2
new file mode 100644
index 0000000..de64c42
--- /dev/null
+++ b/roles/vmm/templates/autoinstall.conf.j2
@@ -0,0 +1,12 @@
+System hostname = {{ item.name }}
+Password for root = {{ vmm_default_password }}
+Network interfaces = run0
+IPv4 address for run0 = dhcp
+Public ssh key for user = {{ vmm_default_ssh_key }}
+Which disk is the root disk = sd0
+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
+HTTP Server = cdn.openbsd.org
+Server = {{ ansible_default_ipv4.gateway }}
+Set name(s) = -all bsd* base* comp* man*
diff --git a/roles/vmm/templates/hostname.j2 b/roles/vmm/templates/hostname.j2
deleted file mode 100644
index 68b989a..0000000
--- a/roles/vmm/templates/hostname.j2
+++ /dev/null
@@ -1 +0,0 @@
-add {{ vmm.switch.interface_host }}
diff --git a/roles/vmm/templates/httpd.conf.j2 b/roles/vmm/templates/httpd.conf.j2
new file mode 100644
index 0000000..ed9feb6
--- /dev/null
+++ b/roles/vmm/templates/httpd.conf.j2
@@ -0,0 +1,4 @@
+server "autoinstall" {
+ listen on * port 80
+ root "/htdocs/autoinstall"
+}
diff --git a/roles/vmm/templates/vm.conf.j2 b/roles/vmm/templates/vm.conf.j2
index d45c398..8653616 100644
--- a/roles/vmm/templates/vm.conf.j2
+++ b/roles/vmm/templates/vm.conf.j2
@@ -6,7 +6,7 @@ switch "{{ vmm_network_switch.name }}" {
}
# virtual machines
-{% for vm in __vms %}
+{% for vm in vmm_vms %}
vm "{{ vm.name }}" {
{% if vm.enabled is defined and not vm.enabled %}
disable
remember that computers suck.