Ancelotti will stay at Real Madrid, maybe he will still spend the rest of his contract at this club and after that announce what the next steps are, of course Real Madrid will also try to convince this experienced coach to stay at the club before finally looking for a replacement who can also still makes Real Madrid a successful club in many competitions. If Ancelotti still chooses Real Madrid and Brazil looks for another coach, Ancelotti will still be in demand by many clubs because his experience is a guarantee that he will be able to provide success for the clubs he will coach.
It seems quite obvious to me that Ancelotti will remain at the club - in the end, with the crisis Real (in the crisis of which he is not to blame at all), he reached the semi-finals of the Champions League and even lost La Liga, but overall it was a good year. If he had such results with the transfers that he requested and would have received, then it would be a different matter, but Mbappe remained at PSG and Real refused to fight for Haaland.
And I do not believe that Ancelotti himself can leave (without dismissal or not renewing the contract) from Real to the national team (of any country). Club football >> national team football if we are talking about top clubs.