Gandalf never reveals his true role in the plan to destroy the ONE RING because he's not allowed. The Valar have ordered him to be mysterious. He obeys them because he's actually working for them.
As tolkien explained in letters to readers,Gandalf is actually an angel, sent to Middle-Earth on a mission. The Valar want to help the creatures of Middle-Earth resist Sauron, so they send spirits to Middle-Earth to do some gentle prodding. Gandalf and some other angels, together called Istari, share that task.(Saruman was one of them, before he became Sauron's servant.) But the Valar don't want to push anybody around, or frighten them the way Sauron does. The Istari are told to keep there true identities a secret. This rule means the creatures of Middle-Earth must decide to fight Sauron because it is the right thing to do, not because they fear the Valar.
Being an angel doesn't make Gandalf perfect, or give him knowledge on how the story will end. As he says often, there is a lot he doesn't know, even about his own task. For all his gifts, he can only hope for the best. And he, like the other members of the Fellowship, is being tested. He passes the test when he sacrifices himself by fighting the fiery Balrog so his friends can escape. He actually dies, because the bodies the Istari are given to hide their identities make them as vulnerable as other creations; but because of his generous act, his spirit is placed in a new body and he is given greater powers than before. Gandalf's friends notice small changes in his appearance because he is truly a new being.