Created
August 4, 2014 16:32
-
-
Save bloodearnest/b2e69d5ad59536c051ce to your computer and use it in GitHub Desktop.
md5_check.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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