title: Getting the version number of a package in ubuntu for use in Ansible
body: <p>I need to write a command that returns only a version number of a package, something like:</p>
  
  <p><code>docker --version
  Docker version 1.10.3, build 20f81dd</code></p>
  
  <p>But that returns only the 1.10.3 part. </p>
  
  <p>I need this for an Ansible playbook. Trying to parse the <code>--version</code> works only if the package is installed, but when it isn't it throws errors. I'm hesitant to interprete the error as an absence of the package, an can't find anything that suits my needs.</p>
  
  <p>I've tried several commands:</p>
  
  <p><code>dpkg -l 'docker' | grep 'Version'
  apt-cache policy docker | grep Installed</code></p>
  
  <p>Both do their work, but Ansible gets huge amounts of excess data (as in every package file and their info, and that's no good if there are a lot of machines sending all that data around)</p>
  
  <p>Is this even possible? Or should I look for a work-around?</p>
  
  <p>Many thanks!</p>