I ran into the same issue with Confirm Hosts with error message “Registering” / “Registration with the server failed”, for HDP 2.1 installation.
In my case, I had incorrectly changed the url_port to 4080 and secured_url_port to 8443 in ambari-agent.ini based on an older version of installation documentation (HDP 1.x) by mistake. Correcting url_port back to 8440 and secured_url_port to 8441 in ambari-agent.ini (correct default ports for HDP 2.x) fixed the problem.
Correct default config in ambari-agent.ini:
[server]
hostname=<ambari server hostname>
url_port=8440
secured_url_port=8441