Use an associative array to store the certificate names per role and environment.
#! /bin/bash
unset -v envs
declare -A envs
while IFS='| ' read -r certname role env; do
envs["$role.$env"]+="$certname"$'\n'
done < /tmp/inventory.list
for e in "${!envs[@]}" ; do
printf '%s\n' "[$e]" "${envs[$e]}"
done
To sort the sections, you can print the keys, sort them, and then read them back and output the associated values:
for e in "${!envs[@]}" ; do
echoprintf '%s\n' "$e"
done | sort | while read -r e ; do
echo "[$e]"
printf '%s\n' echo"[$e]" "${envs[$e]}"
done