---

  - name: Set up output directory
    file: path={{ outputpath }} state={{ item }}
    with_items:
      - absent
      - directory

  - name: Check if Xen exists
    stat: path={{ chrootpath }}/boot/xen.gz
    register: xen_present

  - include: packaging_xen.yml
    when: xen_present.stat.exists == True

  - name: Grab full path to latest chroot kernel
    shell: ls -dt {{ chrootpath }}/boot/vmlin* | head -1
    register: kernel_path

  - name: Grab full path to latest chroot initrd
    shell: ls -dt {{ chrootpath }}/boot/initr* | head -1
    register: initrd_path

  - name: Copy kernel/initrd to output directory
    shell: "{{ item }}"
    with_items:
      - cp {{ kernel_path['stdout'] }} {{ outputpath }}/vmlinuz
      - cp {{ initrd_path['stdout'] }} {{ outputpath }}/initrd.img

  - include: packaging_debian.yml
    when: hostvars[chrootpath]['ansible_distribution'] == "Debian"

  - include: packaging_redhat.yml
    when: hostvars[chrootpath]['ansible_os_family'] == "RedHat"

  - include: packaging_opensuse.yml
    when: hostvars[chrootpath]['ansible_os_family'] == "Suse"

  - include: packaging_ubuntu.yml
    when: hostvars[chrootpath]['ansible_distribution'] == "Ubuntu"

---

  - name: Set up output directory
    file: path={{ outputpath }} state={{ item }}
    with_items:
      - absent
      - directory

  - name: Check if Xen exists
    stat: path={{ chrootpath }}/boot/xen.gz
    register: xen_present

  - include: packaging_xen.yml
    when: xen_present.stat.exists == True

  - name: Grab full path to latest chroot kernel
    shell: ls -dt {{ chrootpath }}/boot/vmlin* | grep -v "fallback" | head -1
    register: kernel_path

  - name: Grab full path to latest chroot initrd
    shell: ls -dt {{ chrootpath }}/boot/initr* | grep -v "fallback" | head -1
    register: initrd_path

  - name: Copy kernel/initrd to output directory
    shell: "{{ item }}"
    with_items:
      - cp {{ kernel_path['stdout'] }} {{ outputpath }}/vmlinuz
      - cp {{ initrd_path['stdout'] }} {{ outputpath }}/initrd.img

  - include: packaging_debian.yml
    when: hostvars[chrootpath]['ansible_distribution'] == "Debian"

  - include: packaging_redhat.yml
    when: hostvars[chrootpath]['ansible_os_family'] == "RedHat"

  - include: packaging_opensuse.yml
    when: hostvars[chrootpath]['ansible_os_family'] == "Suse"

  - include: packaging_ubuntu.yml
    when: hostvars[chrootpath]['ansible_distribution'] == "Ubuntu"

Fix this later, but ensure we don't pick up any debug kernels
Fix this later, but ensure we don't pick up any debug kernels
