title: Best way to check for installed yum package/rpm version in Ansible and use it
body: <p>I've been getting my feet wet with Ansible (2.0.0.2) on CentOS 7. I'm trying to obtain a version from an installed rpm/yum package, but ran into a warning message when running the script.</p>
  <p>Ansible script:</p>
  <pre><code>---
  - name: Get version of RPM
    shell: yum list installed custom-rpm | grep custom-rpm | awk '{print $2}' | cut -d'-' -f1
    register: version
    changed_when: False
  
  - name: Update some file with version
    lineinfile:
      dest: /opt/version.xml
      regexp: &quot;&lt;version&gt;&quot;
      line: &quot;  &lt;version&gt;{{ version.stdout }}&lt;/version&gt;&quot;
  </code></pre>
  <p>Running this works fine and does what it's supposed to, but it's returning a warning after it executes:</p>
  <blockquote>
  <p>ok: [default] =&gt; {&quot;changed&quot;: false, &quot;cmd&quot;: &quot;yum list installed custom-rpm | grep custom-rpm | awk '{print $2}' | cut -d'-' -f1&quot;, &quot;delta&quot;: &quot;0:00:00.255406&quot;, &quot;end&quot;: &quot;2016-05-17 23:11:54.998838&quot;, &quot;rc&quot;: 0, &quot;start&quot;: &quot;2016-05-17 23:11:54.743432&quot;, &quot;stderr&quot;: &quot;&quot;, &quot;stdout&quot;: &quot;3.10.2&quot;, &quot;stdout_lines&quot;: [&quot;3.10.2&quot;], &quot;warnings&quot;: [&quot;Consider using yum module rather than running yum&quot;]}</p>
  <p><strong>[WARNING]: Consider using yum module rather than running yum</strong></p>
  </blockquote>
  <p>I looked up information for the yum module on the <a href="http://docs.ansible.com/ansible/yum_module.html" rel="nofollow noreferrer">Ansible site</a>, but I don't really want to install/update/delete anything.</p>
  <p>I could simply ignore it or suppress it, but I was curious if there was a better way?</p>