An Ansible playbook to prepare a SmartOS PI for network booting
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.1 KiB

---
# 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: prepare current SmartOS platform image for netbooting on a PXE server
hosts:
- pxe_server
gather_facts: no
vars:
download: False # prior download
notification_recipient: tamas@gerczei.eu
smarthost: mail
smarthost_port: 25
tftp_dir: /data/tftproot
smarthost_pw: !vault |
$ANSIBLE_VAULT;1.1;AES256
39376465636636336265393730313534663564373462616231623166656437643862333864386231
6164323864383232643035323166663064633233646337370a613237353538636364346630323633
37313538363837323662333635616563363333336363386631383565653934333763626133663339
3561366536666639300a393537323937633435356639303736653764653962663665363034373031
36633338653533383164386363363439316263306234656432643931663037326634
image_dir: "{{ tftp_dir }}/smartos"
tftp_user: nobody
tftp_group: nogroup
tasks:
- name: fetch platform image
get_url:
url: 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: ensure directories exist
file:
path: "{{ image_dir }}"
state: directory
become: yes
- 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 }}"
port: "{{ smarthost_port }}"
secure: starttls
username: "{{ smarthost_user | default(notification_recipient) }}"
password: "{{ smarthost_pw }}"
from: "Ansible <noreply@fejezd.be>"
to: "{{ notification_recipient }}"
subject: "SmartOS update ({{ last_release }}) available"
body: "created {{ image_dir }}/{{ last_release }} and {{ tftp_dir }}/smartos.ipxe"
when: tarball is changed