From: nicoo Date: Sat, 24 Nov 2018 22:49:23 +0000 (+0100) Subject: ansible: Make preseed take a provided tmpdir X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=7249e3b0790dcf1a20aa7ed5357ceb47ca5142ed;p=noc.git ansible: Make preseed take a provided tmpdir --- diff --git a/ansible/roles/preseed/tasks/main.yml b/ansible/roles/preseed/tasks/main.yml index 54e348a..8289eb6 100644 --- a/ansible/roles/preseed/tasks/main.yml +++ b/ansible/roles/preseed/tasks/main.yml @@ -1,40 +1,25 @@ -- block: - - name: Make a temporary directory - command: mktemp -d - register: tmpdir +- name: Copy initramfs into position + copy: + remote_src: yes + src: "{{ debian_installer_path | mandatory }}/{{ install_distro }}-{{ install_codename }}/{{ hostvars[hostname].install_cooked.arch | default('amd64') }}/initrd.gz" + dest: "{{ preseed_tmpdir }}/initrd.preseed.gz" - - set_fact: - tmpdir: "{{ tmpdir.stdout }}" - initramfs: "{{ preseed_path | mandatory }}/{{ hostname }}-{{ install_distro }}-{{ install_codename }}.initrd.gz" +- name: Generate preseed file + template: + src: "preseed_{{ install_distro }}-{{ install_codename }}.cfg.j2" + dest: "{{ preseed_tmpdir }}/preseed.cfg" - - name: Copy initramfs into position - copy: - remote_src: yes - src: "{{ debian_installer_path | mandatory }}/{{ install_distro }}-{{ install_codename }}/{{ hostvars[hostname].install_cooked.arch | default('amd64') }}/initrd.gz" - dest: "{{ initramfs }}" +- name: Generate authorized_keys file + authorized_key: + user: root + manage_dir: no + path: "{{ preseed_tmpdir }}/authorized_keys" + key: "{{ ssh_keys | join('\n') }}" - - name: Generate preseed file - template: - src: "preseed_{{ install_distro }}-{{ install_codename }}.cfg.j2" - dest: "{{ tmpdir }}/preseed.cfg" - - - name: Generate authorized_keys file - authorized_key: - user: root - manage_dir: no - path: "{{ tmpdir }}/authorized_keys" - key: "{{ ssh_keys | join('\n') }}" - - - name: Inject files into initramfs - shell: cpio -H newc -o | gzip -9 >> '{{ initramfs }}' - args: - chdir: "{{ tmpdir }}" - stdin: | - preseed.cfg - authorized_keys - - always: - - name: Delete temporary directory - file: - path: "{{ tmpdir }}" - state: absent +- name: Inject files into initramfs + shell: cpio -H newc -o | gzip -9 >> 'initrd.preseed.gz' + args: + chdir: "{{ preseed_tmpdir }}" + stdin: | + preseed.cfg + authorized_keys diff --git a/ansible/roles/usb-install/meta/main.yml b/ansible/roles/usb-install/meta/main.yml index 92826a7..bca7f83 100644 --- a/ansible/roles/usb-install/meta/main.yml +++ b/ansible/roles/usb-install/meta/main.yml @@ -4,5 +4,3 @@ dependencies: - distro: "{{ install_distro }}" codename: "{{ install_codename }}" arch: [ "{{ install.arch | default('amd64') }}" ] - - - role: preseed diff --git a/ansible/roles/usb-install/tasks/main.yml b/ansible/roles/usb-install/tasks/main.yml new file mode 100644 index 0000000..1523aed --- /dev/null +++ b/ansible/roles/usb-install/tasks/main.yml @@ -0,0 +1,22 @@ +--- +- block: + - name: Create temporary workdir + command: mktemp -d + register: tmpdir + + - import_role: + name: preseed + vars: + preseed_tmpdir: "{{ tmpdir.stdout }}" + + - name: Copy the preseed initramfs to the artifacts directory + copy: + src: "{{ tmpdir.stdout }}/initrd.preseed.gz" + dest: "{{ artifacts_dir }}/" + + + always: + - name: Cleanup temporary workdir + file: + path: "{{ tmpdir.stdout }}" + state: absent diff --git a/ansible/roles/vm/install/meta/main.yml b/ansible/roles/vm/install/meta/main.yml index 3aaa137..d5f9520 100644 --- a/ansible/roles/vm/install/meta/main.yml +++ b/ansible/roles/vm/install/meta/main.yml @@ -5,6 +5,3 @@ dependencies: - distro: "{{ install_distro }}" codename: "{{ install_codename }}" arch: [ "{{ hostvars[hostname].install_cooked.arch | default('amd64') }}" ] - - role: preseed - ssh_keys: "{{ hostvars[hostname].ssh_keys }}" - install_interface: enp1s1 diff --git a/ansible/roles/vm/install/tasks/main.yml b/ansible/roles/vm/install/tasks/main.yml index 35f2c8e..f14ea50 100644 --- a/ansible/roles/vm/install/tasks/main.yml +++ b/ansible/roles/vm/install/tasks/main.yml @@ -31,40 +31,67 @@ when: hostname in vmhost_info -- name: define new installer vm - virt: - name: "{{ hostname }}" - command: define - xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}" - vars: - run_installer: yes +- block: + - name: create a temporary workdir + command: mktemp -d + register: tmpdir -- name: start vm - virt: - name: "{{ hostname }}" - state: running + - import_role: + name: preseed + vars: + ssh_keys: "{{ hostvars[hostname].ssh_keys }}" + install_interface: enp1s1 + preseed_tmpdir: "{{ tmpdir.stdout }}" -- name: wait for installer to start - wait_for_virt: - name: "{{ hostname }}" - states: running - timeout: 10 + - name: Make preseed workdir readable by qemu + acl: + path: "{{ tmpdir.stdout }}" + state: present + entity: libvirt-qemu + etype: user + permissions: rx -- debug: - msg: "you can check on the status of the installer running this command 'virsh console {{ hostname }}' on host {{ inventory_hostname }}." + - name: define new installer vm + virt: + name: "{{ hostname }}" + command: define + xml: "{{ lookup('template', 'libvirt-domain.xml.j2') }}" + vars: + run_installer: yes + preseed_tmpdir: "{{ tmpdir.stdout }}" -- name: wait for installer to finish or crash - wait_for_virt: - name: "{{ hostname }}" - states: shutdown,crashed - timeout: 1800 - register: installer_result - failed_when: installer_result.failed or installer_result.state == "crashed" + - name: start vm + virt: + name: "{{ hostname }}" + state: running -- name: undefining installer vm - virt: - name: "{{ hostname }}" - command: undefine + - name: wait for installer to start + wait_for_virt: + name: "{{ hostname }}" + states: running + timeout: 10 + + - debug: + msg: "you can check on the status of the installer running this command 'virsh console {{ hostname }}' on host {{ inventory_hostname }}." + + - name: wait for installer to finish or crash + wait_for_virt: + name: "{{ hostname }}" + states: shutdown,crashed + timeout: 900 + register: installer_result + failed_when: installer_result.failed or installer_result.state == "crashed" + + - name: undefining installer vm + virt: + name: "{{ hostname }}" + command: undefine + + always: + - name: cleanup temporary workdir + file: + path: "{{ tmpdir.stdout }}" + state: absent - name: define new production vm virt: diff --git a/ansible/roles/vm/install/templates/libvirt-domain.xml.j2 b/ansible/roles/vm/install/templates/libvirt-domain.xml.j2 index 81c732a..9119f64 100644 --- a/ansible/roles/vm/install/templates/libvirt-domain.xml.j2 +++ b/ansible/roles/vm/install/templates/libvirt-domain.xml.j2 @@ -7,7 +7,7 @@ hvm {% if run_installer %} {{ debian_installer_path }}/{{ install_distro }}-{{ install_codename }}/{{ hostvars[hostname].install_cooked.arch | default('amd64') }}/linux - {{ preseed_path }}/{{ hostname }}-{{ install_distro }}-{{ install_codename }}.initrd.gz + {{ preseed_tmpdir }}/initrd.preseed.gz console=ttyS0,115200n8 {% endif %} diff --git a/ansible/usb-install.yml b/ansible/usb-install.yml index 7ef386d..069fe2c 100644 --- a/ansible/usb-install.yml +++ b/ansible/usb-install.yml @@ -9,20 +9,17 @@ default: "" private: no - vars: - preseed_path: "{{ global_artifacts_dir }}/{{ hostname }}" - debian_installer_path: "{{ global_cache_dir }}/debian-installer" - pre_tasks: - set_fact: install_cooked: "{{ install }}" network_cooked: "{{ network }}" + artifacts_dir: "{{ global_artifacts_dir }}/{{ hostname }}" - file: state: directory name: "{{ item }}" with_items: - - "{{ preseed_path }}" + - "{{ artifacts_dir }}" - "{{ debian_installer_path }}" roles: @@ -40,7 +37,7 @@ src: "{{ item.value }}" dest: "{{ usbdrive_path }}/{{ item.key }}" with_dict: - initrd.gz: "{{ global_artifacts_dir }}/{{ hostname }}/{{ hostname }}-{{ install_distro }}-{{ install_codename }}.initrd.gz" + initrd.gz: "{{ artifacts_dir }}/initrd.preseed.gz" linux: "{{ global_cache_dir }}/debian-installer/{{ install_distro }}-{{ install_codename }}/{{ install.arch | default('amd64') }}/linux" - name: Generate syslinux configuration