Cognitive dissonance is a case of detecting our own hypocrisy, and hypocrisy is a powerful motivation for finding justifications (excuses) for our action.
Whether people will give in to the desire in any given time depends on two things: the strength of the desire and the strength of the self to resist the urge.
An understanding of the circumstances under which people fail at self-control can provide valuable insights into how to overcome self-control problems.