I didn’t expect coreutils to have a database join hiding in it, but it does. join takes two text files, finds the lines with the same value in a key column and glues them together into one line.
Say hosts.txt has a hostname and an IP address per line, and roles.txt has a hostname and what that machine does. The hostname is the first field in both, which is join’s default key, so this is all it takes:
join <(sort hosts.txt) <(sort roles.txt)
The output starts with the shared field, then the rest of the line from the first file, then the rest from the second. So nas 192.168.1.20 and nas Unraid become nas 192.168.1.20 Unraid. The <(...) part is bash process substitution: it sorts both files on the fly without writing temporary copies.
A few options make it far more useful. -t, sets the separator, for CSV files. -1 2 and -2 3 pick a different key field in the first and second file. -a 1 also prints the lines from file 1 that have no match, which gives you a left join, and -v 1 prints only those unmatched lines. That last one is a quick way to find hosts in your inventory that nobody wrote a role for.
The catch is sorting, and the man page marks it as important: both files must be sorted on the join field. If they aren’t, join misses matches, and GNU join complains when it notices input that is out of order. Sort and join also need to agree on what “sorted” means, so run them under the same locale. For a plain join on the first field the manual suggests sorting with sort -k 1b,1. And join only compares exact values, so NAS and nas won’t match unless you add -i.
Further reading: join(1) manual page