]> git.apps.os.sepia.ceph.com Git - ceph-cm-ansible.git/commitdiff
cobbler_profile: Import kernel/initrd distros
authorZack Cerza <zack@redhat.com>
Tue, 15 Sep 2015 21:23:02 +0000 (15:23 -0600)
committerZack Cerza <zack@redhat.com>
Thu, 17 Sep 2015 00:41:11 +0000 (18:41 -0600)
This will be useful for things like rescue images.

Signed-off-by: Zack Cerza <zack@redhat.com>
roles/cobbler_profile/tasks/download_image.yml [new file with mode: 0644]
roles/cobbler_profile/tasks/import_distro.yml
roles/cobbler_profile/tasks/import_distro_image.yml [new file with mode: 0644]

diff --git a/roles/cobbler_profile/tasks/download_image.yml b/roles/cobbler_profile/tasks/download_image.yml
new file mode 100644 (file)
index 0000000..33f3562
--- /dev/null
@@ -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 ) }}"
index 16742bd90452eed802f06e9e8059b89c4ab8ba8f..43c6ea6abcba60df5b388c550e5f58d13b6cddab 100644 (file)
   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 (file)
index 0000000..848cd49
--- /dev/null
@@ -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