I would rent a car in Bari, if your train is to Bari. If you are interested in seeing Bari for a day or two, rent afterwards, after you leave the city, as Bari is not car friendly.
Vieste is too far and convoluted to visit on a day trip. You need to drive there and stay a couple of nights or even three nights if you want a day trip also to Peschici. It’s a beautiful area especially if you go during beach season, which you are. You can stay here if you wish. Not fancy but perfect.
https://maps.app.goo.gl/KXjqFWPnh4VXyk3z6?g_st=ic
Monopoli, Polignano, on the coast, or Locorotondo, Alberobello in the interior, are all in the same area, so any of them can be used as a base to see the others. Even Ostuni, a bit further south, can be visited from those locations. They are all within 45 min drive from one another. You can also visit Matera on a day trip, but you need over one hour drive, depending on your departure point.
In Alberobello I stayed here.
https://maps.app.goo.gl/btsgDChgbLQ8QzZF8?g_st=ic
Otranto on the coast, or Lecce, slightly in the interior, are further south, and a bit too far to drive from the above, so I would have a separate base for those. Gallipoli is another place you can visit from either. In your shoes, since you are going in summer, I’d choose Otranto (I like beaches), however Lecce at night is magical. But it’s only 45 min away, so you could visit Lecce on a day trip from Otranto and drive back late after dinner. In Otranto I have stayed here a couple of times. They have underground parking on the premises, for a daily fee.
https://maps.app.goo.gl/wPBFZS8Jodt1fuUQA?g_st=ic