title: Is there an elegant way to check file integrity with md5 in ansible using md5 files fetched from server?
body: <p>I have several files on a server that I need to download from an <code>ansible playbook</code>, but because the connection has good chances of interruption I would like to check their integrity after download.</p>
  
  <p>I'm considering two approaches:</p>
  
  <ol>
  <li>Store the md5 of those files in ansible as vars</li>
  <li>Store the md5 of those files on the server as files with the extension .md5. Such a pair would look like: <code>file.extension</code> and <code>file.extension.md5</code>.</li>
  </ol>
  
  <p>The <strong>first</strong> approach introduces overhead in maintaining the md5s in ansible. So everytime someone adds a new file, he needs to make sure he adds the md5 in the right place.</p>
  
  <p>But as an advantage, there is a solution for this, using the built in check from <code>get_url</code> action in conjunction with <code>checksum=md5</code>. E.g.:</p>
  
  <pre><code>action: get_url: url=http://example.com/path/file.conf dest=/etc/foo.conf checksum=md5:66dffb5228a211e61d6d7ef4a86f5758
  </code></pre>
  
  <p>The <strong>second</strong> approach is more elegant and the narrows the responsibility. When someone adds a new file on the server, he will make sure to add the <code>.md5</code> as well and won't even need to use the ansible playbooks.</p>
  
  <p>Is there a way to use the <code>checksum</code> approach to match the md5 from a file?</p>