Improvements needed for DT-OTIC and NCTU deploys

- Add text/debug boot mode
- Add ability to specify network interfaces manually during install
- Documentation fixes
- Run 'apt update' in prepare, to help pass CI

Change-Id: Ie341d003b499ef2d22f2d58c38eb41016df93d5a
diff --git a/README.md b/README.md
index 12d7f0a..66d56bc 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,8 @@
 
 Configures PXE and iPXE related boot scripts and images on an web server.
 
+See the `ipxe-build` repo for building iPXE payload images.
+
 The iPXE `boot.ipxe` script:
 
 - Has a menu that reports system information and network status
@@ -17,17 +19,36 @@
 
 For fully automated installation, separate Debian/Ubuntu preseed files are
 created based on the serial number of the device (and possibly other criteria
-like MAC address in the future).
+like MAC address in the future).  Hosts are defined in the pxeboot_hosts list,
+which has these options:
 
-Documentation of the preseed process:
+- `domain`: Domain extension for the host
+- `hostname`: Hostname of the system
+- `serial`: Serial number, must match the SMBIOS supplied serial for server to
+  boot properly.
+- `iface`: (optional) Network interface to use when setting up the system.
+  This is primarily to work around this bug which can cause the wrong interface
+  to be selected in the install process:
+  https://bugs.launchpad.net/ubuntu/+source/netcfg/+bug/713385
 
-- Contents of the preseed file: https://help.ubuntu.com/18.04/installation-guide/amd64/apbs04.html
+Documentation of the preseed process can be found in these links:
+
+- Contents of the preseed file:
+  https://help.ubuntu.com/18.04/installation-guide/amd64/apbs04.html
+
 - All preseed configuration options: https://preseed.debian.net/debian-preseed/
 
+- iPXE docs on preseed files and kernel arguments:
+  https://ipxe.org/appnote/debian_preseed
+
 ## Example Playbook
 
 ```yaml
 - hosts: all
+  vars:
+    pxeboot_hosts:
+      - {domain: 'example.com', hostname: 'server1', serial: 'abc123'}
+      - {domain: 'example.com', hostname: 'server2', serial: 'abc123', iface: 'eno2'}
   roles:
     - pxeboot
 
diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml
new file mode 100644
index 0000000..387f291
--- /dev/null
+++ b/molecule/default/prepare.yml
@@ -0,0 +1,15 @@
+---
+# pxeboot molecule/default/verify.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+
+- name: Prepare for pxeboot role
+  hosts: all
+
+  pre_tasks:
+
+    - name: update apt cache
+      apt:
+        update_cache: true
diff --git a/templates/boot.ipxe.j2 b/templates/boot.ipxe.j2
index e58def9..648c3ef 100644
--- a/templates/boot.ipxe.j2
+++ b/templates/boot.ipxe.j2
@@ -23,6 +23,7 @@
 item --gap --             ------------------------- Operating systems ------------------------------
 item --key u ub1804       Ubuntu 18.04 Installer
 item --key u ub1804a      Ubuntu 18.04 Installer (fully automatic)
+item --key u ub1804adt    Ubuntu 18.04 Installer (fully automatic, debug, text)
 item --gap --             ------------------------- Diagnostics ------------------------------------
 item --key m memtest      Memtest
 item --gap --             ------------------------- Other ------------------------------------------
@@ -77,7 +78,6 @@
 echo Booting Ubuntu 18.04 Installer
 kernel ${http_server_url}/ubuntu1804/linux
 initrd ${http_server_url}/ubuntu1804/initrd.gz
-# imgargs {{ pxeboot_ubuntu1804_linux_args }}
 boot || goto failed
 
 # Ubuntu 18.04 autoinstall
@@ -87,5 +87,12 @@
 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
-# imgargs {{ pxeboot_ubuntu1804_linux_args }}
+boot || goto failed
+
+# Ubuntu 18.04 autoinstall, text-mode, debug
+:ub1804adt
+echo Booting Ubuntu 18.04 Installer, text mode, debug
+kernel ${http_server_url}/ubuntu1804/linux initrd=initrd.gz initrd=preseed.cfg DEBIAN_FRONTEND=text BOOT_DEBUG=2
+initrd ${http_server_url}/ubuntu1804/initrd.gz
+initrd ${http_server_url}/ubuntu1804/${serial}_preseed.cfg preseed.cfg
 boot || goto failed
diff --git a/templates/ubuntu1804_preseed.cfg.j2 b/templates/ubuntu1804_preseed.cfg.j2
index 3212a14..759a0df 100644
--- a/templates/ubuntu1804_preseed.cfg.j2
+++ b/templates/ubuntu1804_preseed.cfg.j2
@@ -23,7 +23,11 @@
 d-i clock-setup/ntp-server string ntp.ubuntu.com
 
 # network and hostname
+{% if 'iface' in item %}
+d-i netcfg/choose_interface select {{ item['iface'] }}
+{% else %}
 d-i netcfg/choose_interface select auto
+{% endif %}
 d-i netcfg/hostname string {{ item['hostname'] }}
 d-i netcfg/get_domain string {{ item['domain'] }}
 d-i hw-detect/load_firmware boolean true