You've waited more than 2 years for the position to come open inside your company.
The person in the spot was rumored to be retiring soon and she finally turned in the paperwork.
It was no secret you wanted the job, especially since you visited one on one with the key senior people who would be involved in the process and let them know. They all said the same thing, that you would be a good fit for the job.
But, when the dust settled from the interview process they selected someone else...an outside candidate.
What happened to the mantra the company espoused of growing its talent and having a preference for promoting from within? Was that just lip service? Possibly. But, the bigger likelihood is that the decision makers didn't really see you as being ready for the role.
It's time to see the handwriting on the wall.
Advancement within this company is not likely, especially in the near term. The decision makers have an image of you that does not align with what they want for the next level up. Your best pathway up is to, first, move out.
Channel your energies into making a new first impression somewhere else versus letting your seething anger cement a negative one at the current job.