Robots in realistic environments require the capability of adapting themselves to different conditions and task requirements regarding motion tracking performances, interaction forces, and payload conditions. Therefore, an online impedance modulation during the task execution represents a critical prerequisite for the robots operating in real-world environments, remaining an open research topic today. This work presents a novel task-based online impedance modulation with stability online verified. The method allows modulating the robot impedance following the task requirements. The method considers the motion tracking performance requested by the task and the expected task payload or interaction forces to derive the robot impedance. Appropriate impedance levels are also maintained to ensure the stability of the modulated robot impedance. The method is successfully verified on the CENTAURO robot.