-- 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: generate authorized_keys file
+ authorized_key:
+ user: root
+ path: "{{ tmpdir }}/authorized_keys"
+ key: "{{ hostvars[vmname].ssh_keys | default(noc_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