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 }
--- /dev/null
+---
+# 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
--- /dev/null
+---
+# 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