From 02bcb091f7e4a3468ed689b8492535c095266cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20G=C3=A9rczei?= Date: Sat, 3 Feb 2018 17:20:27 +0100 Subject: [PATCH] working prototype: Ansible re-write of the former shell and Chef code --- .gitignore | 1 + smartos-updater.yml | 73 +++++++++++++++++++++++++++++++++++++++++++++ smartos_ipxe.j2 | 43 ++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 .gitignore create mode 100644 smartos-updater.yml create mode 100644 smartos_ipxe.j2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8b42eb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.retry diff --git a/smartos-updater.yml b/smartos-updater.yml new file mode 100644 index 0000000..d215a67 --- /dev/null +++ b/smartos-updater.yml @@ -0,0 +1,73 @@ +--- +# TODO: for now we take the PXE environment for granted, so won't install and configure DHCP and TFTP servers; that should become another block defaulting not to be processed +- name: update the SmartOS platform image on the PXE server + hosts: + - pxe_server + gather_facts: no + vars: + notification_recipient: tamas@gerczei.eu + smarthost: mail + tftp_dir: /data/tftproot + image_dir: "{{ tftp_dir }}/smartos" + tftp_user: tftp + tftp_group: tftp + download: false # prior download + tasks: + + - name: fetch platform image + get_url: + src: https://us-east.manta.joyent.com/Joyent_Dev/public/SmartOS/platform-latest.tgz # no Manta at eu-ams-1 + dest: /var/tmp/ + when: download + + - name: obtain provided platform image + copy: + src: /var/tmp/platform-latest.tgz + dest: /tmp/ + remote_src: yes + register: tarball + + - name: process new tarball + block: + + - name: extract new platform image + unarchive: + src: /tmp/platform-latest.tgz + dest: "{{ image_dir }}" + extra_opts: + - --transform + - 's/^platform-//;s/i86pc/platform\/i86pc/' + remote_src: yes + owner: "{{ tftp_user }}" + group: "{{ tftp_group }}" + become: yes + + - name: find images + find: + paths: "{{ image_dir }}" + file_type: directory + register: found_images + + - name: determine latest release + set_fact: + last_release: "{{ ( found_images.files | sort(attribute='mtime',reverse=true) | first )['path'] | basename }}" + + - name: generate iPXE configuration + template: + src: smartos_ipxe.j2 + dest: "{{ tftp_dir }}/smartos.ipxe" + owner: "{{ tftp_user }}" + group: "{{ tftp_group }}" + backup: yes + become: yes + + - name: send e-mail notification + mail: + host: "{{ smarthost }}" + from: "Raspi Root " + to: "{{ notification_recipient }}" + subject: "SmartOS update ({{ last_release }}) available" + body: "created {{ image_dir }}/{{ last_release }} and {{ tftp_dir }}/smartos.ipxe" + + when: tarball|changed + diff --git a/smartos_ipxe.j2 b/smartos_ipxe.j2 new file mode 100644 index 0000000..b6f920d --- /dev/null +++ b/smartos_ipxe.j2 @@ -0,0 +1,43 @@ +#!ipxe +# courtesy of MerlinDMC, slightly modified by tgerczei +# {{ ansible_managed }} + +set smartos-build {{ last_release }} + +:start +menu Welcome to iPXE's Boot Menu +item +item --gap -- ------------------------- Operating systems ------------------------------ +item smartos Boot SmartOS (${smartos-build}) +item smartos_noimport Boot SmartOS (${smartos-build}) noimport +item --gap -- ------------------------------ Utilities --------------------------------- +item shell Enter iPXE shell +item reboot Reboot +item +item exit Exit (boot local disk) +choose --default smartos --timeout 5000 target && goto ${target} + +:shell +echo Type exit to get the back to the menu +shell +set menu-timeout 0 +goto start + +:reboot +reboot + +:exit +exit + +:smartos +kernel /smartos/${smartos-build}/platform/i86pc/kernel/amd64/unix -B console=text,smartos=true +initrd /smartos/${smartos-build}/platform/i86pc/amd64/boot_archive +boot +goto start + +:smartos_noimport +kernel /smartos/${smartos-build}/platform/i86pc/kernel/amd64/unix -B console=text,smartos=true,noimport=true +initrd /smartos/${smartos-build}/platform/i86pc/amd64/boot_archive +boot +goto start +