Cognitive dissonance occurs when there is a conflict between a belief you hold and a behavior, new information, or a conflicting belief. The "dissonance" in this case causes discomfort, necessitating a change in the person's behavior or beliefs to alleviate it. The most famous example in history is the Aesop fable of Sour Grapes. In the fable, a fox tries to get grapes that look delicious (belief) but are out of reach. After trying and failing (action/reality that conflicts with the belief and causes discomfort), the fox says to himself, "Oh, well. They were probably sour, anyway." By changing the belief from thinking they were delicious to thinking they were sour, the fox's distress from not being able to reach the grapes is reduced.
Humans do this in a variety of cases. For example, if they think that they are great at an activity and fail, they either adjust their beliefs that they are good, add a new belief that something happened externally that prevented them from succeeding, or they try the activity over and over again until they succeed so they don't have to change their belief. It happens when someone has a strong political belief and a scientific study provides resulting information that shows their recommended policy would not be effective. It happens when someone believes that they're a good person but them finds themselves having done something rude or mean to someone else.
As you can see, most people use the term to describe something negative: someone is being dumb and refuses to correct himself or herself, or they are faced with reality and have to do something about their beliefs so their entire worldview isn't shattered. And, unfortunately, psychology doesn't do very much to find positive ways to use their findings—something that bothered several psychologists so much that they created the field of Positive Psychology to overcome it. So, how can cognitive dissonance be a good thing, and how can you use it to have a happier life?
Well, there are two use cases that are most important to enable positive outcomes:
In both cases, those dreary uses of cognitive dissonance mentioned at the beginning of this post would imply that your ignoring of contradictory evidence or changing of negative beliefs was delusion, but clearly anyone who wants something in their lives needs to fight the urge to "face reality" since there will always be a million reasons why you should do nothing or not try if you look for them. However, there are plenty of reasons why you should do something and keep trying, if only because you love the thing you're doing or goal you're striving for. That should be enough in and of itself for you to fit it into your life. I say that emphatically because if you change your beliefs so that you never take a shot doing something you love or going after something you want, you might regret it for the rest of your life.
One of the attitudes that bothers me is this "if you can't be the best at something, don't do it" attitude that so many spectators in the "peanut gallery" seem to have. I faced this one time as a teenager when, being a Pittsburgher, I said that my favorite team was (naturally) the Pittsburgh Steelers and the person I was talking to said that they were terrible and that the Rams were the best (implying that I should like them the best because they were the best team). Seriously, who cares? While everyone wants to watch the top performers in their field (hence why they make many times more than everyone else, such as top authors that sell millions of books vs. the 95%+ that sell less than 5,000), but that doesn't mean that everything else is stupid and not worth caring about. If you like playing a sport and you're not the best, who cares? If you like a field but you won't necessarily be the most famous or accomplished, who cares? How is that for an alleviation of cognitive dissonance for you: "I don't have to succeed today or be the best ever tomorrow; I can just do something because I love the process, the outcome, or the value that that outcome delivers to others."
In the movie Memento, the main character said near the end (spoiler part of the quotation removed): "Will I lie to myself to be happy? In your case Teddy...yes I will." Will you tell yourself what you need to hear to be happy? We all do, and you have to if you don't want to make yourself miserable for the rest of your life. Maybe it's something as simple as the Sour Grapes story where you tell yourself that a path that was unavailable to you must not have been the right one for you. Maybe it's that you choose to believe in an afterlife so that you feel better at the possibility of seeing your loved ones again (even though you can't prove it). Maybe it's that you tell yourself that you can do it even against all odds and all evidence to the contrary. Obviously, you don't want to do anything or believe anything that could cause harm to come to you, but holding beliefs that might not fit with reality if they might make you more likely to succeed (via self-fulfilling prophecy, priming, or other psychological mechanisms) or simply be happy? While that's a much longer debate to be had by philosophers and ethicists, you know my main conclusion on the matter: whatever optimizes your growth or minimizes (unnecessary) harm to yourself or others.