Ants release chemicals when they die that attract other ants, to fight off the threat. This is annoying, because squishing an ant that bit you is likely to attract more bitey ants.
Do ants have a chemical signal for “all ye who enter here, either turn back or abandon all hope”? Can you teach a hive to fear a certain place? Or do they just keep coming forever?
You are actually asking two questions, both rather complicated.
After a quick glance at the literature, I’d say that there are some chemicals that induce avoidance.
But I was frankly too lazy to look into the learning aspect.