]> git.apps.os.sepia.ceph.com Git - ceph-cm-ansible.git/commitdiff
Add cobbler_role profile
authorZack Cerza <zack@redhat.com>
Thu, 14 May 2015 00:05:22 +0000 (18:05 -0600)
committerZack Cerza <zack@redhat.com>
Thu, 14 May 2015 17:49:29 +0000 (11:49 -0600)
Signed-off-by: Zack Cerza <zack@redhat.com>
cobbler.yml
roles/cobbler_profile/defaults/main.yml [new file with mode: 0644]
roles/cobbler_profile/tasks/download_iso.yml [new file with mode: 0644]
roles/cobbler_profile/tasks/import_distro.yml [new file with mode: 0644]
roles/cobbler_profile/tasks/main.yml [new file with mode: 0644]

index 741c671fb1fbf799dd9db141db5920b1da616e21..ff4911854231b571f189760bb60707d58e51a28f 100644 (file)
@@ -3,3 +3,8 @@
   roles:
     - common
     - cobbler 
+    - { role: cobbler_profile, distro_name: RHEL-6.6-Server-x86_64 }
+    - { role: cobbler_profile, distro_name: RHEL-7.0-Server-x86_64 }
+    - { role: cobbler_profile, distro_name: RHEL-7.1-Server-x86_64 }
+    - { role: cobbler_profile, distro_name: CentOS-7-x86_64 }
+    - { role: cobbler_profile, distro_name: CentOS-6.6-x86_64 }
diff --git a/roles/cobbler_profile/defaults/main.yml b/roles/cobbler_profile/defaults/main.yml
new file mode 100644 (file)
index 0000000..e8022cf
--- /dev/null
@@ -0,0 +1,22 @@
+---
+# Where to download ISOs
+iso_dir: /var/lib/cobbler/isos
+# Mount point to use for ISOs during import
+iso_mount: /mnt/iso
+
+distros:
+  # Distros with empty iso values will be skipped. These dicts will be 
+  # updated with same-named items in an 'extra_distros' var, which can be 
+  # set in the secrets repo.
+  "RHEL-6.6-Server-x86_64":
+      iso: ""
+  "RHEL-7.0-Server-x86_64":
+      iso: ""
+  "RHEL-7.1-Server-x86_64":
+      iso: ""
+  "CentOS-7-x86_64":
+      iso: http://ftp.linux.ncsu.edu/pub/CentOS/7/isos/x86_64/CentOS-7-x86_64-DVD-1503-01.iso
+      kickstart: cephlab_rhel.ks
+  "CentOS-6.6-x86_64":
+      iso: http://ftp.linux.ncsu.edu/pub/CentOS/6.6/isos/x86_64/CentOS-6.6-x86_64-bin-DVD1.iso
+      kickstart: cephlab_rhel.ks
diff --git a/roles/cobbler_profile/tasks/download_iso.yml b/roles/cobbler_profile/tasks/download_iso.yml
new file mode 100644 (file)
index 0000000..e2f4b27
--- /dev/null
@@ -0,0 +1,25 @@
+---
+- name: Create ISO directory
+  file:
+      path: "{{ iso_dir }}"
+      state: directory
+
+- name: Create ISO mountpoint
+  file:
+      path: "{{ iso_mount }}"
+      state: directory
+
+- name: Set ISO name
+  set_fact:
+      iso_name: "{{ distro.iso.split('/')[-1] }}"
+
+- name: Set ISO path
+  set_fact:
+      iso_path: "{{ iso_dir }}/{{ iso_name }}"
+
+- name: Download ISO
+  get_url:
+      url={{ distro.iso }}
+      dest={{ iso_path }}
+  when: profile is defined and profile.stdout == ''
+  register: download
diff --git a/roles/cobbler_profile/tasks/import_distro.yml b/roles/cobbler_profile/tasks/import_distro.yml
new file mode 100644 (file)
index 0000000..7d33c4a
--- /dev/null
@@ -0,0 +1,70 @@
+---
+# This profile will do all the work necessary to create a new distro/profile
+# pair in Cobbler.
+
+# Since this profile will be used several times in the same playbook,
+# mention the distro name each time.
+- name: Distro name
+  debug: var=distro_name
+
+- name: Load extra_distros from secrets
+  set_fact:
+      # The jinja2 templating API allows you to update one dict with
+      # another, but it does so in-place without returning any dict. The
+      # first blob does the updating; the second actually returns the
+      # result.
+      distros: "{{ distros.update(extra_distros|default({})) }}{{ distros}}"
+
+- name: Find distro settings
+  set_fact:
+      distro: "{{ distros[distro_name] }}"
+
+- 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 
+  # ISOs that are internal, but leave the URL out.
+  when: distro.iso != ''
+  register: profile
+  ignore_errors: true
+  changed_when: false
+
+- include: download_iso.yml
+  when: distro.iso != ''
+
+- name: Mount ISO
+  command: mount -o loop {{ iso_path }} {{ iso_mount }}
+  when: download|changed
+  register: mount
+
+- name: Set arch
+  set_fact:
+      arch: "{{ distro.arch|default('x86_64') }}"
+  when: mount is defined and mount.rc == 0
+
+- name: Import the distro (also creates the profile)
+  command: cobbler import --path={{ iso_mount }} --name={{ distro_name }} --arch={{ arch }}
+  register: import
+  when: mount is defined and mount.rc == 0
+
+- name: Unmount ISO
+  command: umount {{ iso_mount }}
+  when: mount is defined and mount.rc == 0
+
+- name: Set kickstart path
+  set_fact:
+    kickstart_path: /var/lib/cobbler/kickstarts/{{ distro.kickstart }}
+  # If either the profile already existed or we successfully imported the
+  # distro, let's see if we need to change the kickstart.
+  when: distro.kickstart is defined and distro.kickstart != '' and
+        ((profile is defined and profile.stdout == distro_name) or
+         (import is defined and import.rc == 0))
+
+- name: Check to see if the kickstart needs updating
+  shell: cobbler profile dumpvars --name={{ distro_name }} | grep '^kickstart :' | awk '{ print $3 }'
+  when: kickstart_path is defined
+  changed_when: false
+  register: kickstart
+
+- name: "Set the profile's kickstart"
+  command: cobbler profile edit --name={{ distro_name }} --kickstart={{ kickstart_path }}
+  when: kickstart is defined and kickstart.stdout != kickstart_path
diff --git a/roles/cobbler_profile/tasks/main.yml b/roles/cobbler_profile/tasks/main.yml
new file mode 100644 (file)
index 0000000..b0d693b
--- /dev/null
@@ -0,0 +1,4 @@
+---
+- include: import_distro.yml
+  tags:
+    - distros