All due respect to LadyHistory, because I LOVE your blog.
It took a long time to understand this, and I feel grateful for the opportunity to explain it in this format. The reason we are in these countries is not just “because of oil”. That is an overly simplistic answer. It’s true. It’s 100% true. But it’s missing the details, and the details are the answer to your question.
People from Europe that come to the US are sometimes under the impression that it’s easy to see all kinds of stuff in the US in one trip. A foot tour of Manhattan - and only Manhattan, none of the outer Burroughs - could be a whole week with a good guide. That’s just one city, and it’s a major tourist attraction.
Now. I live in Missouri, on a farm. We grow corn and soy beans. Every piece of equipment out here runs on either gasoline or diesel. Solar power and wind power are novelties that don’t actually work hard enough or long enough for us to use them and make money. When you farm, equipment breaks. That is part of the deal. You figure it into your expenses. When a tractor breaks, it costs more than money. It costs time. And that means I have spent many long nights driving all over the state, or even out of state for parts, because we are trying to get the harvest done on time. I spend hours a day in a tractor, or hours a day in my truck going to get parts for the tractors.
Why am I talking about farming?
Because the product of our farming is part of what the United States exports to other countries. International Trade. We get to have gasoline for - right now, I think it was $2.25 a gallon in town.
In London, UK - it is currently $5.79 a gallon. More than double what we pay. 
If you think about it... a brand new Ford Mustang was like, $6500.00 or something in the mid 70s, and gasoline was *famously* $.75 a gallon. Today, a Mustang is $40k, easy. And Gas is only $2.25.
Our relationships with countries that are ideologically appalling to most Americans - like Saudi Arabia, for example - are due to trade negotiations.
Which brings us to the military. The United States Armed Forces are... mind boggling powerful. Google what it is like to fight us. There is a Reddit thread on what it feels like to fight the US Military, and the general consensus I got was “overwhelming”. Now, from a trade standpoint, that is a REALLY good bargaining tool to bring to the table.
Especially when most of the industry involved in exporting US goods -like farming- relies upon the fundamental basis that gasoline is $2.25 a gallon right now.
So, to answer you directly, our military is deployed to other countries because it maintains our economy, and the president doesn’t pull them back because that would be renegging on multiple trade deals that we will never know about unless they get broken and then we’d all be pretty fucked.