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.

90 lines
3.1 KiB

  1. ---
  2. # 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
  3. - name: prepare current SmartOS platform image for netbooting on a PXE server
  4. hosts:
  5. - pxe_server
  6. gather_facts: no
  7. vars:
  8. download: False # prior download
  9. notification_recipient: tamas@gerczei.eu
  10. smarthost: mail
  11. smarthost_port: 25
  12. tftp_dir: /data/tftproot
  13. smarthost_pw: !vault |
  14. $ANSIBLE_VAULT;1.1;AES256
  15. 39376465636636336265393730313534663564373462616231623166656437643862333864386231
  16. 6164323864383232643035323166663064633233646337370a613237353538636364346630323633
  17. 37313538363837323662333635616563363333336363386631383565653934333763626133663339
  18. 3561366536666639300a393537323937633435356639303736653764653962663665363034373031
  19. 36633338653533383164386363363439316263306234656432643931663037326634
  20. image_dir: "{{ tftp_dir }}/smartos"
  21. tftp_user: nobody
  22. tftp_group: nogroup
  23. tasks:
  24. - name: fetch platform image
  25. get_url:
  26. url: https://us-east.manta.joyent.com/Joyent_Dev/public/SmartOS/platform-latest.tgz # no Manta at eu-ams-1
  27. dest: /var/tmp/
  28. when: download
  29. - name: obtain provided platform image
  30. copy:
  31. src: /var/tmp/platform-latest.tgz
  32. dest: /tmp/
  33. remote_src: yes
  34. register: tarball
  35. - name: ensure directories exist
  36. file:
  37. path: "{{ image_dir }}"
  38. state: directory
  39. become: yes
  40. - name: process new tarball
  41. block:
  42. - name: extract new platform image
  43. unarchive:
  44. src: /tmp/platform-latest.tgz
  45. dest: "{{ image_dir }}"
  46. extra_opts:
  47. - --transform
  48. - 's/^platform-//;s/i86pc/platform\/i86pc/'
  49. remote_src: yes
  50. owner: "{{ tftp_user }}"
  51. group: "{{ tftp_group }}"
  52. become: yes
  53. - name: find images
  54. find:
  55. paths: "{{ image_dir }}"
  56. file_type: directory
  57. register: found_images
  58. - name: determine latest release
  59. set_fact:
  60. last_release: "{{ ( found_images.files | sort(attribute='mtime',reverse=true) | first )['path'] | basename }}"
  61. - name: generate iPXE configuration
  62. template:
  63. src: smartos_ipxe.j2
  64. dest: "{{ tftp_dir }}/smartos.ipxe"
  65. owner: "{{ tftp_user }}"
  66. group: "{{ tftp_group }}"
  67. backup: yes
  68. become: yes
  69. - name: send e-mail notification
  70. mail:
  71. host: "{{ smarthost }}"
  72. port: "{{ smarthost_port }}"
  73. secure: starttls
  74. username: "{{ smarthost_user | default(notification_recipient) }}"
  75. password: "{{ smarthost_pw }}"
  76. from: "Ansible <noreply@fejezd.be>"
  77. to: "{{ notification_recipient }}"
  78. subject: "SmartOS update ({{ last_release }}) available"
  79. body: "created {{ image_dir }}/{{ last_release }} and {{ tftp_dir }}/smartos.ipxe"
  80. when: tarball is changed