A constructive approach to a class of ergodic HJB equations with nonsmooth cost