summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2018-01-06 01:28:07 +0100
committerChristian Pointner <equinox@spreadspace.org>2018-01-06 01:28:07 +0100
commit976ff426048195261bc3d458f30228d0a720e1da (patch)
tree59418801946540f9f0fa5d377b323d9b1fa4251a
parentstopping deamon befor purging shouldn't be necessary and breaks idempotence (diff)
added role to prepare host scaleway hosts for dkms
-rw-r--r--host_playbooks/emc-test.yaml1
-rw-r--r--roles/scaleway-dkms/files/my_scw-fetch-kernel-sources23
-rw-r--r--roles/scaleway-dkms/handlers/main.yml3
-rw-r--r--roles/scaleway-dkms/tasks/main.yml26
4 files changed, 53 insertions, 0 deletions
diff --git a/host_playbooks/emc-test.yaml b/host_playbooks/emc-test.yaml
index 812e4758..e1442b2d 100644
--- a/host_playbooks/emc-test.yaml
+++ b/host_playbooks/emc-test.yaml
@@ -7,3 +7,4 @@
- role: sshserver
- role: zsh
- role: admin-user
+ - role: scaleway-dkms
diff --git a/roles/scaleway-dkms/files/my_scw-fetch-kernel-sources b/roles/scaleway-dkms/files/my_scw-fetch-kernel-sources
new file mode 100644
index 00000000..7116ae24
--- /dev/null
+++ b/roles/scaleway-dkms/files/my_scw-fetch-kernel-sources
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# this is based on:
+# https://github.com/scaleway/kernel-tools#how-to-build-a-custom-kernel-module
+
+# Determine versions
+arch="$(uname -m)"
+release="$(uname -r)"
+upstream="${release%%-*}"
+local="${release#*-}"
+
+# Get kernel sources
+mkdir -p /usr/src
+wget -O "/usr/src/linux-${upstream}.tar.xz" "https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-${upstream}.tar.xz"
+tar xf "/usr/src/linux-${upstream}.tar.xz" -C /usr/src/
+ln -fns "/usr/src/linux-${upstream}" /usr/src/linux
+ln -fns "/usr/src/linux-${upstream}" "/lib/modules/${release}/build"
+
+# Prepare kernel
+zcat /proc/config.gz > /usr/src/linux/.config
+printf 'CONFIG_LOCALVERSION="%s"\nCONFIG_CROSS_COMPILE=""\n' "${local:+-$local}" >> /usr/src/linux/.config
+wget -O /usr/src/linux/Module.symvers "http://mirror.scaleway.com/kernel/${arch}/${release}/Module.symvers"
+make -C /usr/src/linux prepare modules_prepare
diff --git a/roles/scaleway-dkms/handlers/main.yml b/roles/scaleway-dkms/handlers/main.yml
new file mode 100644
index 00000000..896fe523
--- /dev/null
+++ b/roles/scaleway-dkms/handlers/main.yml
@@ -0,0 +1,3 @@
+---
+- name: fetch kernel sources
+ command: /usr/local/sbin/my_scw-fetch-kernel-sources
diff --git a/roles/scaleway-dkms/tasks/main.yml b/roles/scaleway-dkms/tasks/main.yml
new file mode 100644
index 00000000..5dda15f6
--- /dev/null
+++ b/roles/scaleway-dkms/tasks/main.yml
@@ -0,0 +1,26 @@
+---
+- name: install build deps
+ with_items:
+ - build-essential
+ - libssl-dev
+ apt:
+ name: "{{ item }}"
+ state: present
+
+- name: install (sadly missing) script to fetch kernel sources
+ copy:
+ src: my_scw-fetch-kernel-sources
+ dest: /usr/local/sbin/
+ mode: 0755
+ notify: fetch kernel sources
+
+- name: check if sources are already initialized
+ stat:
+ path: "/lib/modules/{{ ansible_kernel }}/build"
+ follow: yes
+ register: build_directory
+ changed_when: build_directory.stat.exists == False
+ notify: fetch kernel sources
+
+- name: fetch kernel sources
+ meta: flush_handlers