Clean up heat env file code (undercloud)

There's a lot of boilerplate in this section of code which makes it a
bit hard to read and increases the chance of inconsistencies creeping
in. Also jq is called about 20 times when it only needs to be called
twice.

(Undercloud; overcloud version at
I6d7a7081e15452f1ca090610a3a068cfe30b531b)

Change-Id: I09cb2dfad514c85feffd1ed7fee7a059879a091a
Merge "Clean up heat env file code (undercloud)"