title: Evaluating return code in ansible conditional
body: <p>I'm working on automating a task which needs to append the latest version of software to a file. I don't want it to do this multiple times for the same version.</p>
  <p>It looks at the following example file:</p>
  <pre><code>var software releases = new Array(
      &quot;4.3.0&quot;,
      &quot;4.4.0&quot;,
      &quot;4.5.0&quot;,
      &quot;4.7.0&quot;,
      &quot;4.8.0&quot;,
      &quot;4.11.0&quot;,
      &quot;4.12.1&quot;,
      &quot;4.14.0&quot;,
      &quot;4.15.0&quot;,
      &quot;4.16.0&quot;,
  );
  </code></pre>
  <p>the defaults main.yml would pass in something like</p>
  <pre><code>VERSION: 4.16.2
  </code></pre>
  <p>code</p>
  <pre><code>- name: register version check
    shell: cat /root/versions.js | grep -q {{VERSION}}
    register: current_version
  
  - debug: msg=&quot;The registered variable output is {{ current_version.rc }}&quot;
  
  - name: append to versions.js
    lineinfile:
      dest: /root/versions.js
      regexp: '^\);'
      insertbefore: '^#\);'
      line: &quot;    \&quot;{{VERSION}}\&quot;,\n);&quot;
      owner: root
      state: present
      when: current_version.rc == 1
  </code></pre>
  <p>problem: the debug message is evaluating current_version.rc and showing me boolean values based on the grep commands output, but I can't re-use this in the <code>when</code> conditional to determine if the task should be run.</p>
  <p>Edit: the output:</p>
  <pre><code>PLAY [localhost] **************************************************************
  
  GATHERING FACTS ***************************************************************
  ok: [localhost]
  
  TASK: [test | register version check] *****************************************
  failed: [localhost] =&gt; {&quot;changed&quot;: true, &quot;cmd&quot;: &quot;cat /root/versions.js | grep -q 3.19.2&quot;, &quot;delta&quot;: &quot;0:00:00.003570&quot;, &quot;end&quot;: &quot;2015-12-17 00:24:49.729078&quot;, &quot;rc&quot;: 1, &quot;start&quot;: &quot;2015-12-17 00:24:49.725508&quot;, &quot;warnings&quot;: []}
  
  FATAL: all hosts have already failed -- aborting
  
  PLAY RECAP ********************************************************************
             to retry, use: --limit @/root/site.retry
  
  localhost                  : ok=1    changed=0    unreachable=0    failed=1
  </code></pre>