Can set iTerm2 tab colors from the command line?
It appears a script like this could work for you. This is using zsh, but should work or only require a little bit of editing to work with bash. 

Essentially what it does is aliases ssh to this color ssh command which changes the color of the tab and then runs ssh.