Add the ability to pick preseed based on MAC address

Change-Id: Idfa5085389d227c8f96fec42f94b069424085ba5
diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml
index e8c2494..7796764 100644
--- a/molecule/default/molecule.yml
+++ b/molecule/default/molecule.yml
@@ -27,5 +27,11 @@
         ansible_python_interpreter: /usr/bin/python3
       ubuntu-18.04-priv:
         ansible_python_interpreter: /usr/bin/python3
+    group_vars:
+      all:
+        pxeboot_hosts:
+          - {domain: 'example.com', hostname: 'server1', serial: 'abc123'}
+          - {domain: 'example.com', hostname: 'server2', serial: 'def456', iface: 'eno2'}
+          - {domain: 'example.com', hostname: 'server3', mac_address: '01:23:45:ab:cd:ef'}
 verifier:
   name: ansible
diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml
index 387f291..00ea0fe 100644
--- a/molecule/default/prepare.yml
+++ b/molecule/default/prepare.yml
@@ -8,8 +8,18 @@
 - name: Prepare for pxeboot role
   hosts: all
 
+  vars:
+    acme_username: "www-data"  # make independent of the acme role
+    vhosts:
+      - name: "boot.example.com"
+        default_server: true
+        autoindex: true
+
   pre_tasks:
 
     - name: update apt cache
       apt:
         update_cache: true
+
+  roles:
+    - nginx
diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml
index 6a9563e..56f747d 100644
--- a/molecule/default/verify.yml
+++ b/molecule/default/verify.yml
@@ -7,6 +7,23 @@
 - name: Verify
   hosts: all
   tasks:
-  - name: example assertion
-    assert:
-      that: true
+
+    - name: Check that preseed files are available (Serial)
+      uri:
+        url: "http://127.0.0.1/ubuntu1804/{{ item['serial'] }}_preseed.cfg"
+        status_code: 200
+        return_content: true
+      register: ps_serial
+      failed_when: "item['hostname'] not in ps_serial.content"
+      with_items: "{{ pxeboot_hosts }}"
+      when: "'serial' in item and item.serial"
+
+    - name: Check for preseed files (MAC)
+      uri:
+        url: "http://127.0.0.1/ubuntu1804/{{ item['mac_address'] }}_preseed.cfg"
+        status_code: 200
+        return_content: true
+      register: ps_mac
+      failed_when: "item['hostname'] not in ps_mac.content"
+      with_items: "{{ pxeboot_hosts }}"
+      when: "'mac_address' in item and item.mac_address"
diff --git a/tasks/ubuntu1804.yml b/tasks/ubuntu1804.yml
index f7468e5..ba04deb 100644
--- a/tasks/ubuntu1804.yml
+++ b/tasks/ubuntu1804.yml
@@ -22,7 +22,7 @@
     mode: "0644"
   with_items: "{{ pxeboot_ubuntu1804_files }}"
 
-- name: Create preseed files
+- name: Create preseed files (serial)
   template:
     src: "ubuntu1804_preseed.cfg.j2"
     dest: "{{ pxeboot_web_root }}/ubuntu1804/{{ item['serial'] }}_preseed.cfg"
@@ -30,3 +30,14 @@
     group: "{{ pxeboot_groupname }}"
     mode: "0644"
   with_items: "{{ pxeboot_hosts }}"
+  when: "'serial' in item and item.serial"
+
+- name: Create preseed files (MAC)
+  template:
+    src: "ubuntu1804_preseed.cfg.j2"
+    dest: "{{ pxeboot_web_root }}/ubuntu1804/{{ item['mac_address'] | lower }}_preseed.cfg"
+    owner: "{{ pxeboot_username }}"
+    group: "{{ pxeboot_groupname }}"
+    mode: "0644"
+  with_items: "{{ pxeboot_hosts }}"
+  when: "'mac_address' in item and item.mac_address"
diff --git a/templates/boot.ipxe.j2 b/templates/boot.ipxe.j2
index 28721e4..462696a 100644
--- a/templates/boot.ipxe.j2
+++ b/templates/boot.ipxe.j2
@@ -23,7 +23,8 @@
 item --key d deb10        Debian 10 Installer
 item --key f deb10f       Debian 10 Installer (nonfree firmware)
 item --key u ub1804       Ubuntu 18.04 Installer
-item --key a ub1804a      Ubuntu 18.04 Installer (fully automatic)
+item --key a ub1804as     Ubuntu 18.04 Installer (fully automatic, serial)
+item --key a ub1804am     Ubuntu 18.04 Installer (fully automatic, MAC)
 item --key t ub1804adt    Ubuntu 18.04 Installer (fully automatic, debug, text)
 item --gap --             ------------------------- Utilities --------------------------------------
 item --key m memtest      Memtest
@@ -95,15 +96,24 @@
 initrd ${http_server_url}/ubuntu1804/initrd.gz
 boot || goto failed
 
-# Ubuntu 18.04 autoinstall
+# Ubuntu 18.04 autoinstall, serial
 #  https://ipxe.org/appnote/debian_preseed
-:ub1804a
-echo Booting Ubuntu 18.04 Installer
+:ub1804as
+echo Booting Ubuntu 18.04 Installer (autoinstall, serial)
 kernel ${http_server_url}/ubuntu1804/linux initrd=initrd.gz initrd=preseed.cfg
 initrd ${http_server_url}/ubuntu1804/initrd.gz
 initrd ${http_server_url}/ubuntu1804/${serial}_preseed.cfg preseed.cfg
 boot || goto failed
 
+# Ubuntu 18.04 autoinstall, MAC
+#  https://ipxe.org/appnote/debian_preseed
+:ub1804am
+echo Booting Ubuntu 18.04 Installer (autoinstall, MAC)
+kernel ${http_server_url}/ubuntu1804/linux initrd=initrd.gz initrd=preseed.cfg
+initrd ${http_server_url}/ubuntu1804/initrd.gz
+initrd ${http_server_url}/ubuntu1804/${net0/mac}_preseed.cfg preseed.cfg
+boot || goto failed
+
 # Ubuntu 18.04 autoinstall, text-mode, debug
 :ub1804adt
 echo Booting Ubuntu 18.04 Installer, text mode, debug