When ssh with PublicIpAddress fails, run ssh with PrivateIpAddress. I'm handling this way but it doesn't seem to work, ssh with PublicIpAddress exits with code 255 and doesn't try ssh with PrivateIpAddress.
for _, machine := range selected {
err := ssh(machine.KeyName, Username, machine.PublicIpAddress)
if err != nil {
err = ssh(machine.KeyName, Username, machine.PrivateIpAddress)
}
if err != nil {
fmt.Println(err)
}
}
SSH func
func ssh(keyname string, user string, address string) error {
var err error
//
if err := cmd.Run(); err != nil {
fmt.Println(err.Error())
}
return err
}