Ambushes in the middle of an ongoing combat occur fairly frequently, so it is important for a DM to have a rules interpretation on this situation. Here's mine:
Step 1) Determine if the ambusher is aware of the enemy. A ghoul underground cannot see, but can still probably hear the combat depending on how deep it is underneath. The DC to hear an ongoing combat is -10 + 1 per 10 feet of distance + a situational modifier for the dampening effect of the earth.
Step 2) If the ambusher is aware, it goes at the top of the round (highest initiative). If unaware, it rolls initiative.
Step 3) Determine if the enemy is aware of the ambusher before the ambusher takes an action. If the ghoul is lying still underground, then it is effectively invisible and silent.
Step 4) Take the ambusher's action. If the action includes an attack (through a charge, 5 foot step and attack, or readied action) and the enemy was unaware of the ambusher, then the ambusher was effectively invisible during the attack and the enemy does not get his dex bonus. In this case the only action the ghoul could take to make an attack would be a readied action IMO. Crawling out of the ground should not be a 5 foot step for a non-burrowing creature. I would consider the ghoul to be in a prone position, but it would get a cover bonus if it was only half out of the ground.
Step 5) If the ambusher has another action left, determine again if the enemy is aware of it before executing the action. In this case the ghoul is out in the light, so it is automatically visible.
Step 1) Determine if the ambusher is aware of the enemy. A ghoul underground cannot see, but can still probably hear the combat depending on how deep it is underneath. The DC to hear an ongoing combat is -10 + 1 per 10 feet of distance + a situational modifier for the dampening effect of the earth.
Step 2) If the ambusher is aware, it goes at the top of the round (highest initiative). If unaware, it rolls initiative.
Step 3) Determine if the enemy is aware of the ambusher before the ambusher takes an action. If the ghoul is lying still underground, then it is effectively invisible and silent.
Step 4) Take the ambusher's action. If the action includes an attack (through a charge, 5 foot step and attack, or readied action) and the enemy was unaware of the ambusher, then the ambusher was effectively invisible during the attack and the enemy does not get his dex bonus. In this case the only action the ghoul could take to make an attack would be a readied action IMO. Crawling out of the ground should not be a 5 foot step for a non-burrowing creature. I would consider the ghoul to be in a prone position, but it would get a cover bonus if it was only half out of the ground.
Step 5) If the ambusher has another action left, determine again if the enemy is aware of it before executing the action. In this case the ghoul is out in the light, so it is automatically visible.