title: How to validate that a file has a specific substring with Ansible?
body: <p>I would like to have an <code>assert</code> or <code>fail</code> task in my Ansible play that validates that the right code build was deployed. The deployment comes with a <code>version.properties</code> file which has the build info I care about.</p>
  
  <p>The 'correct' code version comes from a vars file and is called <code>desired_build_id</code>.</p>
  
  <p>How can I validate that my <code>version.properties</code> mentions this build ID? Some sort of substring search?</p>
  
  <p>I've tried the following:</p>
  
  <pre><code>--- 
  - name: Validate deployment success
    hosts: app-nodes
    tasks:
      - name: Read version.properties file
        shell: cat /path/to/version.properties
        register: version_prop_content
  
      - fail: Wrong build ID found in version.properties
        when: desired_build_id not in version_prop_content.stdout 
  </code></pre>
  
  <p>However, that gives a error: <code>error while evaluating conditional: esired_build_id not in version_prop_content.stdout</code></p>
  
  <p>What's the right syntax for this? Or, is there a better way?</p>