use lineinfile instead of the complicated 3-step dance