From 2ebacb64b6a3de79bf173d73329cc574e19665a5 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 13 May 2015 18:05:22 -0600 Subject: [PATCH] Add cobbler_role profile Signed-off-by: Zack Cerza --- cobbler.yml | 5 ++ roles/cobbler_profile/defaults/main.yml | 22 ++++++ roles/cobbler_profile/tasks/download_iso.yml | 25 +++++++ roles/cobbler_profile/tasks/import_distro.yml | 70 +++++++++++++++++++ roles/cobbler_profile/tasks/main.yml | 4 ++ 5 files changed, 126 insertions(+) create mode 100644 roles/cobbler_profile/defaults/main.yml create mode 100644 roles/cobbler_profile/tasks/download_iso.yml create mode 100644 roles/cobbler_profile/tasks/import_distro.yml create mode 100644 roles/cobbler_profile/tasks/main.yml diff --git a/cobbler.yml b/cobbler.yml index 741c671f..ff491185 100644 --- a/cobbler.yml +++ b/cobbler.yml @@ -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 index 00000000..e8022cf8 --- /dev/null +++ b/roles/cobbler_profile/defaults/main.yml @@ -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 index 00000000..e2f4b271 --- /dev/null +++ b/roles/cobbler_profile/tasks/download_iso.yml @@ -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 index 00000000..7d33c4ad --- /dev/null +++ b/roles/cobbler_profile/tasks/import_distro.yml @@ -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 index 00000000..b0d693b0 --- /dev/null +++ b/roles/cobbler_profile/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- include: import_distro.yml + tags: + - distros -- 2.47.3