This will be useful for things like rescue images.
Signed-off-by: Zack Cerza <zack@redhat.com>
--- /dev/null
+---
+- name: Check to see if the kernel exists
+ stat: path={{ kernel_path }} get_checksum=no get_md5=no
+ register: kernel_stat
+
+- name: Check to see if the initrd exists
+ stat: path={{ initrd_path }} get_checksum=no get_md5=no
+ register: initrd_stat
+
+- name: Download kernel
+ get_url:
+ url={{ distro.kernel }}
+ dest={{ kernel_path }}
+ sha256sum={{ distro.kernel_sha256 }}
+ when: profile is defined and profile.stdout == ''
+ register: download_kernel
+
+- name: Download initrd
+ get_url:
+ url={{ distro.initrd }}
+ dest={{ initrd_path }}
+ sha256sum={{ distro.initrd_sha256 }}
+ when: profile is defined and profile.stdout == ''
+ register: download_initrd
+
+- name: Set files_exist if the required files are in place
+ set_fact:
+ files_exist: "{{ ( kernel_stat.stat.exists or download_kernel|changed) and ( initrd_stat.stat.exists or download_initrd|changed ) }}"
set_fact:
distro: "{{ distros[distro_name] }}"
+- name: Fail if an iso is provided in combination with either a kernel or initrd
+ fail: msg="Cannot specify both 'iso' and 'kernel' or 'initrd'. distro '{{ distro_name }}'"
+ when: distro.iso != '' and (distro.kernel is defined or distro.initrd is defined)
+
+- name: Set profile_type to iso
+ set_fact:
+ profile_type: 'iso'
+ when: distro.iso is defined and distro.iso != ''
+
+- name: Set profile_type to image
+ set_fact:
+ profile_type: 'image'
+ when: (distro.kernel is defined and distro.kernel != '') and (distro.initrd is defined and distro.initrd != '')
+
- name: Determine if distro profile exists
command: cobbler profile find --name {{ distro_name }}
- # Skip if the iso field is empty; this allows us to mention distros with
+ # Skip if the profile_type is empty; this allows us to mention distros with
# ISOs that are internal, but leave the URL out.
- when: distro.iso != '' or distro.kernel != ''
+ when: profile_type|default('') != ''
register: profile
ignore_errors: true
changed_when: false
- include: import_distro_iso.yml
- when: distro.iso != ''
+ when: profile_type|default('') == 'iso'
-# make sure to define profile_found?
+- include: import_distro_image.yml
+ when: profile_type|default('') == 'image'
# If either the profile already existed or we successfully imported the
# distro, we might want to update other options in the profile. i.e. kickstarts
--- /dev/null
+---
+- name: Set image scratch directory
+ set_fact:
+ image_path: "{{ other_image_dir }}/{{ distro_name }}"
+
+- name: Set kernel name
+ set_fact:
+ kernel_name: "{{ distro.kernel.split('/')[-1] }}"
+
+- name: Set kernel path
+ set_fact:
+ kernel_path: "{{ other_image_dir }}/{{ kernel_name }}"
+
+- name: Set initrd name
+ set_fact:
+ initrd_name: "{{ distro.initrd.split('/')[-1] }}"
+
+- name: Set initrd path
+ set_fact:
+ initrd_path: "{{ other_image_dir }}/{{ initrd_name }}"
+
+- include: download_image.yml
+ when: distro.kernel != ''
+
+- name: Set arch
+ set_fact:
+ arch: "{{ distro.arch|default('x86_64') }}"
+ when: download_kernel is defined and download_kernel|success
+
+- name: Add the distro to cobbler
+ command: cobbler distro add --kernel {{ kernel_path }} --initrd {{ initrd_path }} --name {{ distro_name }}
+ when: download|changed or (files_exist and
+ profile is defined and profile.stdout == '')
+ register: import
+
+- name: Add the profile to cobbler
+ command: cobbler profile add --name {{ distro_name }} --distro {{ distro_name }}
+ when: import is defined and import.stdout == ''
+ register: import