From 782d606069d9dbeebe85a2a797a077c0c177de4b Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 13 Jun 2018 03:54:11 +0200 Subject: [PATCH] vm/install: Bake the preseed file into the initrd --- ansible/roles/vm/host/handlers/main.yml | 5 --- ansible/roles/vm/host/tasks/main.yml | 9 ----- ansible/roles/vm/install/tasks/main.yml | 36 +++++++++++++++++--- .../vm/install/templates/libvirt-domain.xml.j2 | 4 +-- .../templates/preseed_debian-stretch.cfg.j2 | 16 ++++----- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/ansible/roles/vm/host/handlers/main.yml b/ansible/roles/vm/host/handlers/main.yml index f6b5f80..6541dd8 100644 --- a/ansible/roles/vm/host/handlers/main.yml +++ b/ansible/roles/vm/host/handlers/main.yml @@ -1,9 +1,4 @@ --- -- name: restart inetd - service: - name: openbsd-inetd - state: restarted - - name: restart haveged service: name: haveged diff --git a/ansible/roles/vm/host/tasks/main.yml b/ansible/roles/vm/host/tasks/main.yml index a7b018c..dc9a0a3 100644 --- a/ansible/roles/vm/host/tasks/main.yml +++ b/ansible/roles/vm/host/tasks/main.yml @@ -2,8 +2,6 @@ - name: install dependencies apt: name: - - atftpd - - openbsd-inetd - qemu-kvm - libvirt-bin - python-libvirt @@ -17,13 +15,6 @@ path: /etc/default/haveged notify: restart haveged -- name: configure tftpd via inetd - lineinfile: - regexp: "^#?({{ vm_host.network.ip }}:)?tftp" - line: "{{ vm_host.network.ip }}:tftp dgram udp4 wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd --tftpd-timeout 300 --retry-timeout 5 --maxthread 10 --verbose=5 {{ vm_host.installer.preseed_path }}" - path: /etc/inetd.conf - notify: restart inetd - - name: make sure installer directories exists with_items: - "{{ vm_host.installer.path }}" diff --git a/ansible/roles/vm/install/tasks/main.yml b/ansible/roles/vm/install/tasks/main.yml index 1603483..505ec1d 100644 --- a/ansible/roles/vm/install/tasks/main.yml +++ b/ansible/roles/vm/install/tasks/main.yml @@ -1,8 +1,36 @@ --- -- name: generate preseed file - template: - src: "preseed_{{ vmdistro }}-{{ vmdistcodename }}.cfg.j2" - dest: "{{ vm_host.installer.preseed_path }}/vm-{{ vmname }}-{{ vmdistro }}-{{ vmdistcodename }}.cfg" +- block: + - name: Make a temporary directory + command: mktemp -d + register: tmpdir + + - set_fact: + tmpdir: "{{ tmpdir.stdout }}" + initramfs: "{{ vm_host.installer.preseed_path }}/vm-{{ vmname }}-{{ vmdistro }}-{{ vmdistcodename }}.initrd.gz" + + - name: Copy initramfs into position + copy: + remote_src: yes + src: "{{ vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ hostvars[vmname].vm_install_cooked.arch | default('amd64') }}/initrd.gz" + dest: "{{ initramfs }}" + + - name: generate preseed file + template: + src: "preseed_{{ vmdistro }}-{{ vmdistcodename }}.cfg.j2" + dest: "{{ tmpdir }}/preseed.cfg" + + - name: Inject files into initramfs + shell: cpio -H newc -o | gzip -9 >> {{ initramfs }} + args: + chdir: "{{ tmpdir }}" + stdin: | + preseed.cfg + + always: + - name: Delete temporary directory + file: + path: "{{ tmpdir }}" + state: absent - name: create disks for vm with_dict: "{{ hostvars[vmname].vm_install_cooked.disks.virtio | default({}) | combine(hostvars[vmname].vm_install_cooked.disks.scsi | default({})) }}" diff --git a/ansible/roles/vm/install/templates/libvirt-domain.xml.j2 b/ansible/roles/vm/install/templates/libvirt-domain.xml.j2 index c8a2d95..c39b904 100644 --- a/ansible/roles/vm/install/templates/libvirt-domain.xml.j2 +++ b/ansible/roles/vm/install/templates/libvirt-domain.xml.j2 @@ -7,8 +7,8 @@ hvm {% if run_installer %} {{ vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ hostvars[vmname].vm_install_cooked.arch | default('amd64') }}/linux - {{ vm_host.installer.path }}/{{ vmdistro }}-{{ vmdistcodename }}/{{ hostvars[vmname].vm_install_cooked.arch | default('amd64') }}/initrd.gz - console=ttyS0,115200n8 auto=true interface=auto url=tftp://{{ hostvars[inventory_hostname]['ansible_' + (vm_host.installer.net_if | replace('-', '_'))].ipv4.address }}/vm-{{ vmname }}-{{ vmdistro }}-{{ vmdistcodename }}.cfg netcfg/choose_interface=enp1s1 netcfg/disable_autoconfig=true netcfg/get_ipaddress={{ hostvars[vmname].vm_network_cooked.primary.ip }} netcfg/get_netmask={{ hostvars[vmname].vm_network_cooked.primary.mask }} netcfg/get_gateway={{ hostvars[vmname].vm_network_cooked.primary.gateway }} netcfg/get_nameservers="{{ hostvars[vmname].vm_network_cooked.nameservers | join(' ') }}" netcfg/confirm_static=true netcfg/get_hostname={{ vmname }} netcfg/get_domain={{ hostvars[vmname].vm_network_cooked.domain }} + {{ vm_host.installer.preseed_path }}/vm-{{ vmname }}-{{ vmdistro }}-{{ vmdistcodename }}.initrd.gz + console=ttyS0,115200n8 {% endif %} diff --git a/ansible/roles/vm/install/templates/preseed_debian-stretch.cfg.j2 b/ansible/roles/vm/install/templates/preseed_debian-stretch.cfg.j2 index 5b1b3f8..6d48fd2 100644 --- a/ansible/roles/vm/install/templates/preseed_debian-stretch.cfg.j2 +++ b/ansible/roles/vm/install/templates/preseed_debian-stretch.cfg.j2 @@ -7,14 +7,14 @@ d-i debian-installer/country string AT d-i debian-installer/locale string en_US.UTF-8 d-i keyboard-configuration/xkb-keymap select us - -#d-i netcfg/choose_interface select enp1s1 -#d-i netcfg/disable_autoconfig boolean false -#d-i netcfg/get_ipaddress string {{ hostvars[vmname].vm_network_cooked.primary.ip }} -#d-i netcfg/get_netmask string {{ hostvars[vmname].vm_network_cooked.primary.mask }} -#d-i netcfg/get_gateway string {{ hostvars[vmname].vm_network_cooked.primary.gateway }} -#d-i netcfg/get_nameservers string {{ hostvars[vmname].vm_network_cooked.nameservers | join(' ') }} -#d-i netcfg/confirm_static boolean true +d-i netcfg/disable_dhcp boolean true +d-i netcfg/choose_interface select enp1s1 +d-i netcfg/disable_autoconfig boolean false +d-i netcfg/get_ipaddress string {{ hostvars[vmname].vm_network_cooked.primary.ip }} +d-i netcfg/get_netmask string {{ hostvars[vmname].vm_network_cooked.primary.mask }} +d-i netcfg/get_gateway string {{ hostvars[vmname].vm_network_cooked.primary.gateway }} +d-i netcfg/get_nameservers string {{ hostvars[vmname].vm_network_cooked.nameservers | join(' ') }} +d-i netcfg/confirm_static boolean true d-i netcfg/get_hostname string {{ vmname }} d-i netcfg/get_domain string {{ hostvars[vmname].vm_network_cooked.domain }} -- 1.7.10.4