ansible: Make preseed take a provided tmpdir
authornicoo <nicoo@realraum.at>
Sat, 24 Nov 2018 22:49:23 +0000 (23:49 +0100)
committernicoo <nicoo@realraum.at>
Sat, 24 Nov 2018 23:33:43 +0000 (00:33 +0100)
ansible/roles/preseed/tasks/main.yml
ansible/roles/usb-install/meta/main.yml
ansible/roles/usb-install/tasks/main.yml [new file with mode: 0644]
ansible/roles/vm/install/meta/main.yml
ansible/roles/vm/install/tasks/main.yml
ansible/roles/vm/install/templates/libvirt-domain.xml.j2
ansible/usb-install.yml

index 54e348a..8289eb6 100644 (file)
@@ -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
index 92826a7..bca7f83 100644 (file)
@@ -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 (file)
index 0000000..1523aed
--- /dev/null
@@ -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
index 3aaa137..d5f9520 100644 (file)
@@ -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
index 35f2c8e..f14ea50 100644 (file)
 
   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:
index 81c732a..9119f64 100644 (file)
@@ -7,7 +7,7 @@
     <type arch='x86_64' machine='pc-0.12'>hvm</type>
 {% if run_installer %}
     <kernel>{{ debian_installer_path }}/{{ install_distro }}-{{ install_codename }}/{{ hostvars[hostname].install_cooked.arch | default('amd64') }}/linux</kernel>
-    <initrd>{{ preseed_path }}/{{ hostname }}-{{ install_distro }}-{{ install_codename }}.initrd.gz</initrd>
+    <initrd>{{ preseed_tmpdir }}/initrd.preseed.gz</initrd>
     <cmdline>console=ttyS0,115200n8</cmdline>
 {% endif %}
     <boot dev='hd'/>
index 7ef386d..069fe2c 100644 (file)
@@ -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