diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..31f3626 --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a977916 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vagrant/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..951c7e3 --- /dev/null +++ b/README.md @@ -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). \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..1b6fecc --- /dev/null +++ b/Vagrantfile @@ -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 diff --git a/playbooks/roles/debian9-hetzner/defaults/main.yml b/playbooks/roles/debian9-hetzner/defaults/main.yml new file mode 100644 index 0000000..9b3eece --- /dev/null +++ b/playbooks/roles/debian9-hetzner/defaults/main.yml @@ -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 diff --git a/playbooks/roles/debian9-hetzner/files/grub b/playbooks/roles/debian9-hetzner/files/grub new file mode 100644 index 0000000..c677f19 --- /dev/null +++ b/playbooks/roles/debian9-hetzner/files/grub @@ -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" \ No newline at end of file diff --git a/playbooks/roles/debian9-hetzner/tasks/main.yml b/playbooks/roles/debian9-hetzner/tasks/main.yml new file mode 100644 index 0000000..cc14320 --- /dev/null +++ b/playbooks/roles/debian9-hetzner/tasks/main.yml @@ -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 diff --git a/playbooks/vagrant.yml b/playbooks/vagrant.yml new file mode 100644 index 0000000..c9d0028 --- /dev/null +++ b/playbooks/vagrant.yml @@ -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