Afghanistan has no oil. Iraq does, but the US showed no interest in taking it for decades. It was most likely pushed by our "greatest ally" there who also has no oil.
The Kurds are our greatest ally in Iraq and they most definitely have lots of oil in addition to letting US operate on their territory in exchange for protecting the oil interests. I suppose you could say that's not us taking the oil but we still get value like we had taken the oil and provided fair market rate to host bases in exchange.
I said fair market rate to host bases. Saddam was definitely not leasing us military at fair market rate in Iraq (or Syria for that matter, where Kurds also host US base).