Duke Energy must act immediately to eliminate sources of groundwater contamination at its coal ash dumps, a judge said Thursday in a ruling that came from a complaint filed in 2012, before a vast spill from one of the utility’s plants coated 70 miles of the Dan River in toxic sludge this year. Environmental groups said in the complaint that despite repeated calls and monitoring wells that showed contaminated groundwater at the ash dumps, regulators failed to take enforcement action. Judge Paul Ridgeway of Wake County Superior Court said state regulators had failed to apply state law properly to the toxic ash pits. He reversed a 2012 ruling by state regulators that interpreted state rules to mean contaminated groundwater did not have to be cleaned up until they assessed the problem.