title: Replacing a word in a file with Ansible
body: <p>I was trying to replace one string in a file. For example:</p>
  
  <pre><code>$PASSWORD="oldpassword"
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>$PASSWORD="newpassword"
  </code></pre>
  
  <p>Here is the Ansible task which should do this:</p>
  
  <pre><code>- name: change password with lineinfile 
    lineinfile:
      dest: test.txt
      regexp: '^$PASSWORD='
      line: '^$PASSWORD="newpassword"'
      state: present
      backrefs: yes 
  </code></pre>
  
  <p>Unfortunately I can't find the reason why it isn't working. I cannot replace it with the new string.</p>
  
  <p>I was also trying without <code>backrefs</code> and the string was added instead of replaced.</p>
  
  <p>Please advise.
  Thank you.</p>