You can establish rack awareness either through Ambari or through your own topology script.
More Information
Set the Rack ID for Ambari
Set the Rack ID Using a Custom Topology Script