Managing NFS and NIS, 2nd Edition - Mike Eisler [120]
Key and variable substitutions
There are two forms of substitutions that are performed in automounter maps: variable substitution and key substitution. Variables are useful for hiding architecture or operating system dependencies when maintaining a uniform naming scheme, while key substitutions impress a degree of regularity on the automounter maps.
Key substitutions
The ampersand (&) expands to the matched key value in a map; it is used in the server:directory path pair to copy key values into directory path component names. Let's say you have a map that lists all the exported directories on your network that exist for the purpose storing users' home directories. Let's call this map auto_home_exports. Initially, this map looks like:
thud -rw thud:/export/home/thud
wahoo -rw wahoo:/export/home/wahoo
mahimahi -rw mahimahi:/export/home/mahimahi
We can rewrite it using key substitution:
thud -rw &:/export/home/&
wahoo -rw &:/export/home/&
mahimahi -rw &:/export/home/&
With the right-hand side rewritten, the map's regular form can be further condensed using the asterisk (*) wildcard:
* -rw &:/export/home/&
The asterisk is a default case. Nothing after it will ever be matched, so it should be the last (or only) entry in the map. It matches all keys, providing a value for the & substitutions that fill in the right-hand side of the map information.
For example, assume that the clients are using the auto_home_exports map for the /home_exports mount point. Every reference through /home_exports matches the wildcard map entry. When a lookup of /home_exports/thud/jan is performed, the automounter gets an RPC request to look up thud in the /home_exports directory. Referring to the indirect map, the automounter finds the wildcard, which matches the key thud. The automounter makes thud the default key, and expands the server:directory component as:
thud:/export/home/thud
This entry is equivalent to a thud-specific entry:
thud -rw thud:/export/home/thud
Special case mappings may be added ahead of the wildcard map entry:
mahimahi2 -rw mahimahi:/export/home/mahimahi2
* -rw &:/export/home/&
Of course, wildcards can get you into trouble as well. Assume that you are using the following simple indirect map for auto_home_exports:
* -rw &:/export/home/&
and a user tries to access /home_exports/foo. The automounter then tries to mount foo:/export/home/foo, but it's probable that no host named foo exists. In this case, the user will get a somewhat puzzling "No such host" error message when the automounter cannot find the server's name in the NIS hosts map.
The concise wildcard-based naming scheme is useful for machines exporting a single home directory, but when multiple home directories are exported from several disks on a server, the one-to-one mapping of home directory names to server names breaks down. If naming conventions permit, you can create hostname aliases in the NIS hosts map that match the additional home directory names, allowing the wildcard map to be used.
To see how this works, let's simplify the following auto_home_exports map for the three servers mahimahi, thud, and wahoo:
mahimahi -rw mahimahi:/export/home/mahimahi
mahimahi2 -rw mahimahi:/export/home/mahimahi2
thud -rw thud:/export/home/thud
thud2 -rw thud:/export/home/thud2
thud3 -rw thud:/export/home/thud3
wahoo -rw wahoo:/export/home/wahoo
Applying wildcard key matching substitution to the regularly named directories shortens the auto_home_exports map so that only the secondary and tertiary home directories are listed:
mahimahi2 -rw mahimahi:/export/home/mahimahi2
thud2 -rw thud:/export/home/thud2
thud3 -rw thud:/export/home/thud3
* -rw &:/export/home/&
Adding hostname aliases for mahimahi and thud to the hosts map condenses the auto_home_servers map even further:
NIS hosts map
192.9.201.5 mahimahi mahimahi2
192.9.201.6 thud thud2 thud3
192.9.201.7 wahoo
auto_home_servers map
* -rw &:/export/home/&
When a reference to /home_exports/thud2/jan is