summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2017-03-17 16:56:55 +0100
committerJonathan Bauer2017-03-17 16:56:55 +0100
commitb5516c8ff47ed02e50821644f788adc14c19ab1c (patch)
tree5ad0d9b69d8f9c8b600a648b8811e2cd9725e45e
parentinitial commit (diff)
downloadansible-dracut-b5516c8ff47ed02e50821644f788adc14c19ab1c.tar.gz
ansible-dracut-b5516c8ff47ed02e50821644f788adc14c19ab1c.tar.xz
ansible-dracut-b5516c8ff47ed02e50821644f788adc14c19ab1c.zip
added basic roles to generate stage3 initramfs
-rw-r--r--.gitignore1
-rw-r--r--README.md20
-rw-r--r--build-dracut-initramfs.yml7
-rw-r--r--dracut-initramfs-builder/defaults/main.yml2
-rw-r--r--dracut-initramfs-builder/files/.placeholder0
-rw-r--r--dracut-initramfs-builder/meta/main.yml3
-rw-r--r--dracut-initramfs-builder/tasks/distro.yml25
-rw-r--r--dracut-initramfs-builder/tasks/main.yml37
-rw-r--r--dracut-initramfs-builder/vars/main.yml2
-rw-r--r--setup-dev-tools/defaults/main.yml2
-rw-r--r--setup-dev-tools/tasks/distro.yml16
-rw-r--r--setup-dev-tools/tasks/main.yml8
12 files changed, 123 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..380f61c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+boot_files/*
diff --git a/README.md b/README.md
index 8768b09..ede4cdc 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,22 @@
# Ansible roles for OpenSLX
+Small collection of ansible roles to build a dracut-based initramfs for network boot.
+The roles currently support both Ubuntu 16.04.2 and CentOS 7.3.
+Currently, it only matches these distribution families but does not check for these exact versions!
+### setup-dev-tools
+Installs basic development packages for the detected distribution:
+
+ Ubuntu: build-essential, cmake, git
+ CentOS: "@development tools", cmake, git
+
+### dracut-initramfs-builder
+Builds the dracut-based initramfs using the dnbd3-rootfs module (see [systemd-init](http://git.openslx.org/openslx-ng/systemd-init.git/)):
+* Install needed dependencies to build dracut for the detected distribution
+* Checkout git repository for systemd-init
+* Build the initramfs for the running kernel
+* Extract both initramfs and kernel out of the virtual machine
+
+Depends on *setup-dev-tools* role (see dracut-initramfs-builder/meta/main.yml).
+
+## Usage
+Use the provided 'build-dracut-initramfs.yml' playbook for the ansible provisioner in your packer template.
diff --git a/build-dracut-initramfs.yml b/build-dracut-initramfs.yml
new file mode 100644
index 0000000..b946805
--- /dev/null
+++ b/build-dracut-initramfs.yml
@@ -0,0 +1,7 @@
+---
+- hosts: "all"
+ gather_facts: yes
+ pre_tasks:
+ - setup:
+ roles:
+ - { role: "dracut-initramfs-builder", packer_version: "0.12.2" }
diff --git a/dracut-initramfs-builder/defaults/main.yml b/dracut-initramfs-builder/defaults/main.yml
new file mode 100644
index 0000000..61e7f27
--- /dev/null
+++ b/dracut-initramfs-builder/defaults/main.yml
@@ -0,0 +1,2 @@
+---
+packer_version: "0.12.2"
diff --git a/dracut-initramfs-builder/files/.placeholder b/dracut-initramfs-builder/files/.placeholder
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/dracut-initramfs-builder/files/.placeholder
diff --git a/dracut-initramfs-builder/meta/main.yml b/dracut-initramfs-builder/meta/main.yml
new file mode 100644
index 0000000..713e243
--- /dev/null
+++ b/dracut-initramfs-builder/meta/main.yml
@@ -0,0 +1,3 @@
+---
+dependencies:
+ - { role: setup-dev-tools }
diff --git a/dracut-initramfs-builder/tasks/distro.yml b/dracut-initramfs-builder/tasks/distro.yml
new file mode 100644
index 0000000..3212eae
--- /dev/null
+++ b/dracut-initramfs-builder/tasks/distro.yml
@@ -0,0 +1,25 @@
+---
+- set_fact:
+ pkgnames:
+ - kernel-devel
+ - fuse-devel
+ - jansson-devel
+ - glib2-devel
+ - pixman-devel
+ - libewf-devel
+ - afflib-devel
+ - device-mapper
+ when:
+ - ansible_distribution == "CentOS"
+- set_fact:
+ pkgnames:
+ - libfuse-dev
+ - libglib2.0-dev
+ - libpixman-1-dev
+ - libewf-dev
+ - libafflib-dev
+ - dmsetup
+ - iputils-arping
+ when:
+ - ansible_distribution == "Ubuntu"
+
diff --git a/dracut-initramfs-builder/tasks/main.yml b/dracut-initramfs-builder/tasks/main.yml
new file mode 100644
index 0000000..9cb25be
--- /dev/null
+++ b/dracut-initramfs-builder/tasks/main.yml
@@ -0,0 +1,37 @@
+---
+- include: tasks/distro.yml
+
+- name: Install dependencies for OpenSLX dracut module
+ package: name={{ item }} state=installed
+ with_items: "{{ pkgnames }}"
+
+- name: Checkout repository of OpenSLX dracut module
+ git:
+ repo: "{{ gitsource }}"
+ dest: "{{ gittarget }}"
+ depth: 1
+- name: Hack: fix dnbd3 blk.h for CentOS (one day this should get fixed in dnbd3 :))
+ replace:
+ dest: "{{ gittarget }}/builder/modules.d/dnbd3-rootfs/scripts/build.sh"
+ regexp: 'make -j4 dnbd3 dnbd3-client'
+ replace: 'sed -i "s/KERNEL_VERSION.*/KERNEL_VERSION\(3, 10, 0\)/g" blk.h && make -j4 dnbd3 dnbd3-client'
+ backup: yes
+ when:
+ - ansible_distribution == "CentOS"
+- name: Build initramfs with dracut
+ shell: "{{ gittarget }}/builder/build-initramfs.sh -s -d -p {{ gittarget }}/initramfs"
+ args:
+ creates: "{{ gittarget }}/initramfs"
+- name: Fetch built initramfs and kernel (+ hack for weird /@ prefix of BOOT_IMAGE)
+ fetch:
+ src: "{{ item }}"
+ dest: "{{ playbook_dir }}/boot_files/"
+ fail_on_missing: yes
+ flat: yes
+ with_items:
+ - "{{ gittarget }}/initramfs"
+ - "{{ ansible_cmdline.BOOT_IMAGE | regex_replace('^/@(/boot/.*)+$', '\\1') }}"
+- name: Cleanup
+ file:
+ path: "{{ gittarget }}"
+ state: absent
diff --git a/dracut-initramfs-builder/vars/main.yml b/dracut-initramfs-builder/vars/main.yml
new file mode 100644
index 0000000..e8f7c48
--- /dev/null
+++ b/dracut-initramfs-builder/vars/main.yml
@@ -0,0 +1,2 @@
+gitsource: "git://git.openslx.org/openslx-ng/systemd-init"
+gittarget: "/opt/systemd-init"
diff --git a/setup-dev-tools/defaults/main.yml b/setup-dev-tools/defaults/main.yml
new file mode 100644
index 0000000..61e7f27
--- /dev/null
+++ b/setup-dev-tools/defaults/main.yml
@@ -0,0 +1,2 @@
+---
+packer_version: "0.12.2"
diff --git a/setup-dev-tools/tasks/distro.yml b/setup-dev-tools/tasks/distro.yml
new file mode 100644
index 0000000..0f120ec
--- /dev/null
+++ b/setup-dev-tools/tasks/distro.yml
@@ -0,0 +1,16 @@
+---
+# This sets the package names for the supported distros.
+- set_fact:
+ pkgnames:
+ - "build-essential"
+ - "cmake"
+ - "git"
+ when:
+ - ansible_distribution == "Ubuntu"
+- set_fact:
+ pkgnames:
+ - "@development tools"
+ - "cmake"
+ - "git"
+ when:
+ - ansible_distribution == "CentOS"
diff --git a/setup-dev-tools/tasks/main.yml b/setup-dev-tools/tasks/main.yml
new file mode 100644
index 0000000..62a176f
--- /dev/null
+++ b/setup-dev-tools/tasks/main.yml
@@ -0,0 +1,8 @@
+---
+# Get packages names for the target distro
+- include: tasks/distro.yml
+
+# Finally lets install those packages
+- name: Install dev tools
+ package: name={{ item }} state=installed
+ with_items: "{{ pkgnames }}"