In part 1 of this story I demonstrated a way to automate the installation of OpenShift 4.7 on bare metal machines using static network configuration.
While this way is much better than booting with the live ISO and manually doing the configuration for every node, we still need to create a separate ISO for each one. So I thought maybe I can take it a step further. Why not use one ISO for all masters and workers? And how can we achieve that? Read on!
The ISOs for masters and workers that we created using the procedure in part 1, differ in only three places. IP, hostname and node role.
The real question is, what is the unique attribute that, in our case, distinguishes one machine from the other? The MAC address of course!
So we can create in advance a lookup table that will translate a MAC address to the corresponding IP address, hostname and role.
At first, I thought about using a Bash associative array but these are one-dimensional, so they can’t be used in our case.
The next best thing is a flat-file database containing rows of data, where each row represents a machine and consists of four, space separated fields in the order MAC, IP, hostname, role. This file will be created in the live environment’s filesystem so that it can be accessed by our Bash script.
So here is our new Ignition file that can be used to create our single ISO:
Our nodemap lookup file is created in /home/core (lines 20–25) and in this example containes two representative rows. The enp0s3.nmconnection file has now a placeholder instead of an actual IP (line 14). Similar placeholders are used in our node.ign file for role (line 64) and hostname (line 85). These files are created before our Bash script starts (lines 26–53). When it runs, the script gets the MAC address (line 34) and uses the powerful awk utility to lookup the IP, hostname and role from the nodemap file (lines 35–37). For more details about this particular awk syntax, see awk’s variable assignment. Finally, it uses sed to replace the placeholders in the files with the actual values.
When the script executes the coreos-install command (line 42), the files have the correct values for the node it is running on.
To convert auto-node.yaml to an Ignition config which will be used to create the ISO, we follow the procedure in part 1.
So there you have it! An automated OpenShift 4.7 bare metal installation using one ISO for the bootstrap and one ISO for all the masters and workers!