> In the first Iraq war, they went in and won. In the second one, it took years to sort of occupy the country.

The objectives for the two wars were incredibly different, making this an apples to oranges comparison. In the first war, the objective was to push Iraqi troops out of Kuwait (achieved) and then to contain the Iraqi military within Iraq (achieved). In the second war, the objectives were much broader and much harder to achieve. They achieved some objectives (toppling the existing government, defeating the existing military), and then utterly failed in nation building and got into a protracted conflict with state and non-state sponsored military groups.

I wouldn't call nation building a failure. It made significant progress.

Some nation building occurred, but mostly corruption. This was after the first war where they deliberately destroyed civilian infrastructure like power plants, water treatment plants, hospitals and such to create a failed nation. A country that was one of the most modern and developed middle eastern countries before the war.