At the end (post-credit) of Avengers: Age of Ultron, Thanos is seen taking the Infinity Gauntlet.
But in Avengers: Infinity War, judging from Eitri's words, his attack on Nidavellir, where he obtained the gauntlet, took place in a small time interval just before the events of Infinity War. There was Thor: Ragnarok between Age of Ultron and Infinity War and Nidavellir was unprotected after Asgard was destroyed in Ragnarok. So, it appears that Thanos attacked Nedavellir after Ragnarok.
So how could Thanos have the Infinity Gauntlet at the end of Avengers: Age of Ultron, given the fact that he attacked the dwarves and made them create the gauntlet just before the events of Avengers: Infinity War?