title: Ansible - Check if string exists in file
body: <p>I'm very new to Ansible</p>
  
  <p>Is it possible to check if a string exists in a file using Ansible. </p>
  
  <p>I want to check is a user has access to a server. 
  this can be done on the server using <code>cat /etc/passwd | grep username</code></p>
  
  <p>but I want Ansible to stop if the user is not there. </p>
  
  <p>I have tried to use the <code>lineinfile</code> but can't seem to get it to return.</p>
  
  <p>code </p>
  
  <pre><code> - name: find
     lineinfile: dest=/etc/passwd
                 regexp=[user]
                 state=present
                 line="user"
  </code></pre>
  
  <p>The code above adds user to the file if he is not there. All i want to do is check. I don't want to modify the file in any way, is this possible </p>
  
  <p>Thanks. </p>