(Photograph = ant with nectary, alexanderwild.com)
Introduction
Nectaries are small glands, often found inside flowers. They secrete nectar that is consumed by pollinators.
The Details
Cacti have nectaries and make nectar too, sometimes you can sip a bit of the sweet liquid in a cactus flower.
However, nectaries are not restricted to flowers. Extrafloral nectaries exist on many plants, and these often attract ants. Why do plants secrete nectar outside of flowers. Why do ants visit the nectaries? One hypothesis is that the ants protect the plant from other insects that would eat the plant. So, in return for food, the ants pay their rent by protection the host cactus.
Additional Reading: Extrafloral Nectaries in Cylindropuntia