title: Running ansible lineinfile twice is adding a line at the end of the file
body: <p>I have a ansible playbook and I want to change a configuration for postgres database:</p>
  
  <pre><code>...
  - name: Configuring postgres
    become: yes
    lineinfile:
      dest: /etc/postgresql/9.5/main/pg_hba.conf
      regexp: "^local   all             postgres                                peer$"
      line:   "local   all             postgres                                trust"
  ....
  </code></pre>
  
  <p>I want to replace <strong>peer</strong> with <strong>trust</strong></p>
  
  <p>in the postgres configuration. When I run the playbook for the first time it works fine as expected. But when I run it 2 or more times, the playbook starts append a new line at the bottom of the file, since the search string is no longer false. How do I prevent ansible from doing this?</p>