Skip to content

Instantly share code, notes, and snippets.

@bloodearnest
Created August 4, 2014 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bloodearnest/b2e69d5ad59536c051ce to your computer and use it in GitHub Desktop.
Save bloodearnest/b2e69d5ad59536c051ce to your computer and use it in GitHub Desktop.
md5_check.py
import os
import hashlib
class FilterModule(object):
def filters(self):
return {
'md5_check': self.md5_check,
}
def md5_check(self, path):
md5_path = '/tmp/ansible_md5_check_%s.md5' % os.path.basename(path)
with open(path) as data:
new_md5 = hashlib.md5(data.read()).hexdigest()
if os.path.exists(md5_path):
with open(md5_path) as md5_file:
old_md5 = md5_file.read()
changed = new_md5 != old_md5
else:
changed = True
with open(md5_path, 'w') as f:
f.write(new_md5)
return changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment