1. Download Clock Work Mod recovery from here
2. Download cwm-root-gtab2.zip to root your device from attachment and copy to external sdcard
3. Download Fix-Recovery to erase install-recovery.sh from attachment and copy to external sdcard
4. Now Turn your device off .
5. Boot into Download-Mode (Power+Vol Down) and press vol up to continue.
6. Start Odin
7. Choose "GT-P31XX_ClockworkMod-Recovery_X.X.X.X.tar" as PDA
8. Connect your Tab
9. Untick Reset Time and Auto Reboot
10. When it show PASS, remove usb cable and hold Vol Up + Power, when Samsung Galaxy Tab screen appear release power button but keep vol up.
11. In CWM recovery, install fix recovery and cwm-root.
12. Now reboot your tab. It should be rooted now.
*Tested in my galaxy tab 2 7" with Android 4.0.4 from OTA update.
All credit go to xda developer