If this is the case,
Rack-A
Master 0 (Ambari)
Master 1 (NameNode Server 1, NameNodeHA)
Rack-B
Master 2 (NameNode Server 2, NameNodeHA)
Master 3 (Yarn, etc...)
Rack-C
Slave 1-10 (DataNode 1-10)
Rack-D
Slave 11-20 (DataNodes 11-20)
Just only set the rack awareness to datanode's racks using by ambari?
Like this
/default
: Master 0, Master 1, Master 2, Master 3
/Rack-C
: Slave 1-10
/Rack-D
: Slave 11-20