From c1df0658d7bb2b0fc8d6e514adae37d624c22a6d Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 15 Sep 2015 15:23:02 -0600 Subject: [PATCH] cobbler_profile: Import kernel/initrd distros This will be useful for things like rescue images. Signed-off-by: Zack Cerza --- .../cobbler_profile/tasks/download_image.yml | 28 +++++++++++++ roles/cobbler_profile/tasks/import_distro.yml | 23 +++++++++-- .../tasks/import_distro_image.yml | 39 +++++++++++++++++++ 3 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 roles/cobbler_profile/tasks/download_image.yml create mode 100644 roles/cobbler_profile/tasks/import_distro_image.yml diff --git a/roles/cobbler_profile/tasks/download_image.yml b/roles/cobbler_profile/tasks/download_image.yml new file mode 100644 index 0000000..33f3562 --- /dev/null +++ b/roles/cobbler_profile/tasks/download_image.yml @@ -0,0 +1,28 @@ +--- +- 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 ) }}" diff --git a/roles/cobbler_profile/tasks/import_distro.yml b/roles/cobbler_profile/tasks/import_distro.yml index 16742bd..43c6ea6 100644 --- a/roles/cobbler_profile/tasks/import_distro.yml +++ b/roles/cobbler_profile/tasks/import_distro.yml @@ -18,19 +18,34 @@ 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 diff --git a/roles/cobbler_profile/tasks/import_distro_image.yml b/roles/cobbler_profile/tasks/import_distro_image.yml new file mode 100644 index 0000000..848cd49 --- /dev/null +++ b/roles/cobbler_profile/tasks/import_distro_image.yml @@ -0,0 +1,39 @@ +--- +- 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 -- 2.39.5