Skip to content

Commit

Permalink
Configure & create OS image using ansible provisioner
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkaholic committed Jan 10, 2020
0 parents commit 1b10dbe
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# EditorConfig helps developers define and maintain consistent
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vagrant/
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# hetzner OS image for debian 9

A provisioner for a vagrant box in order to create an OS image for debian 9 that
can be used with the hetzner installimage tool.

## Notes

hetzner offers a standard image for debian 9. Unfortunately it does not include support
for the latest intel network adapters used dedicated hosts of PX series (and probably others).
9 changes: 9 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Vagrant.configure("2") do |config|
config.vm.box = "bento/debian-9.11"

# Run Ansible from the Vagrant VM
config.vm.provision "ansible_local" do |ansible|
ansible.verbose = "vv"
ansible.playbook = "playbooks/vagrant.yml"
end
end
4 changes: 4 additions & 0 deletions playbooks/roles/debian9-hetzner/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
intel_driver_module: e1000e
intel_driver_version: 3.6.0
intel_driver_download_location: https://downloadmirror.intel.com/15817/eng/{{ intel_driver_module }}-{{ intel_driver_version }}.tar.gz
32 changes: 32 additions & 0 deletions playbooks/roles/debian9-hetzner/files/grub
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="nomodeset consoleblank=0"
GRUB_CMDLINE_LINUX="net.ifnames=1 biosdevname=0 debian-installer=en_US.UTF-8"

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
71 changes: 71 additions & 0 deletions playbooks/roles/debian9-hetzner/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
- name: Download intel driver for network adapter
get_url:
url: "{{ intel_driver_download_location }}"
dest: /root/{{ intel_driver_module }}-{{ intel_driver_version }}.tar.gz
mode: '0440'

- name: Extract network adapter driver
unarchive:
src: /root/{{ intel_driver_module }}-{{ intel_driver_version }}.tar.gz
dest: /root/
remote_src: yes

- name: Run command to get kernel version
command: "uname -r"
register: uname_output

- name: Set kernel version variable
set_fact:
kernel_version: "{{ uname_output.stdout }}"

- name: Install kernel headers
apt:
name: "linux-headers-{{ kernel_version }}"
state: present

- name: Compile network adapter driver
shell: make install
args:
chdir: /root/{{ intel_driver_module }}-{{ intel_driver_version }}/src/

- name: Load network adapter driver module
shell: modprobe {{ intel_driver_module }}

- name: Add network card driver module to /etc/modules
lineinfile:
dest: /etc/modules
regexp: '^{{ intel_driver_module }}'
line: "{{ intel_driver_module }}"

- name: Rename network device
shell: nohup sh -c "ip link set eth0 down && ip link set eth0 name eno1 && ip link set eno1 up"

- name: Copy over grub config files with enabled predictable network devices
copy:
src: files/grub
dest: /etc/default/grub
owner: root
group: root
mode: '0644'

- name: Update grub config
shell: update-grub

- name: Run command to get package timestamp
command: "date +%Y%m%d%H%M%S"
register: date_output

- name: Set package timestamp name
set_fact:
package_timestamp: "{{ date_output.stdout }}"

- name: Create directory for image
file:
path: /osimage
state: directory

- name: Create OS image package
shell: tar zcvf Debian-911-stretch-64-custom-{{ package_timestamp }}.tar.gz /bin /boot /etc /home /lib /lib64 /media /mnt /opt /root /run /sbin /srv /tmp /usr /var
args:
chdir: /osimage
12 changes: 12 additions & 0 deletions playbooks/vagrant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- hosts: all
become: true
vars:
document_root: /vagrant
www_user: vagrant
www_group: vagrant
pre_tasks:
- name: update apt cache
apt: update_cache=yes cache_valid_time=3600
roles:
- debian9-hetzner

0 comments on commit 1b10dbe

Please sign in to comment.