From: Near Portland, OR
Hitler was a staunch anti-communist. The anti-aggression pact between the USSR and Germany came as a huge surprise because of it.
Attacking Russia did have a lot of ideology behind it. Germany was buying lots of oil from the USSR, it fueled most of the early war for Germany, but Hitler thought he could just take the oil as well as all the other resources in the USSR. The Ukraine is a huge grain growing region.
Germany then, as it is now is a very densely populated country. The Germans looked east and saw a lot of sparsely populated land they could use for their large population to grow extra food and just have more room to spread out.
With the Red Army in such chaos, Hitler thought they could take the USSR and they came close to doing it. There are a lot of plausible "what if" scenarios where Hitler takes Moscow and captures Stalin in 1941 and the USSR collapses soon after. The Germans did capture millions of Soviet troops in 1941 and made just about all the gains in the north they made in the entire war in only a few months.
Looking back on history, it was a monumental blunder. Though the Red Army was rebuilding and it was possible that the western Allies would bring the USSR in on their side. If that happened without Germany attacking first, the Russians would be starting from inside the 1939 Polish border. As history proved, it's tough to stop a determined army that wants to march across the plains of eastern Europe.
WitP AE - Test team lead, programmer