From e6b76a59c584eee08ea0e1dff8e5dadd0cb2763a Mon Sep 17 00:00:00 2001 From: Fred Alger Date: Thu, 14 Jun 2012 23:51:30 -0400 Subject: [PATCH 1/2] Make shell outs to md5sum work on FreeBSD and OS X Tested with OS X local connection and Linux remote. The paths to the md5sum and md5 commands are hardcoded to the most common location. This will definitely fail if the commands are elsewhere, or if the md5 command doesn't support the -q 'quiet' option. --- lib/ansible/runner/__init__.py | 6 +++--- library/copy | 4 ++-- library/setup | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 14597a754da..75864036fa6 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -476,8 +476,8 @@ class Runner(object): # compare old and new md5 for support of change hooks local_md5 = None if os.path.exists(dest): - local_md5 = os.popen("md5sum %s" % dest).read().split()[0] - remote_md5 = self._low_level_exec_command(conn, "md5sum %s" % source, tmp, True).split()[0] + local_md5 = os.popen("/usr/bin/md5sum %(file)s 2> /dev/null || /sbin/md5 -q %(file)s" % {"file": dest}).read().split()[0] + remote_md5 = self._low_level_exec_command(conn, "/usr/bin/md5sum %(file)s 2> /dev/null || /sbin/md5 -q %(file)s" % {"file": source}, tmp, True).split()[0] if remote_md5 != local_md5: # create the containing directories, if needed @@ -486,7 +486,7 @@ class Runner(object): # fetch the file and check for changes conn.fetch_file(source, dest) - new_md5 = os.popen("md5sum %s" % dest).read().split()[0] + new_md5 = os.popen("/usr/bin/md5sum %(file)s 2> /dev/null || /sbin/md5 -q %(file)s" % {"file": dest}).read().split()[0] if new_md5 != remote_md5: result = dict(failed=True, msg="md5 mismatch", md5sum=new_md5) return ReturnData(host=conn.host, result=result) diff --git a/library/copy b/library/copy index f9c85ef2bbc..7b5cbb54d3d 100755 --- a/library/copy +++ b/library/copy @@ -60,9 +60,9 @@ if not os.path.exists(src): md5sum = None changed = False if os.path.exists(dest): - md5sum = os.popen("md5sum %s" % dest).read().split()[0] + md5sum = os.popen("/usr/bin/md5sum %(file)s 2> /dev/null || /sbin/md5 -q %(file)s" % {"file": dest}).read().split()[0] -md5sum2 = os.popen("md5sum %s" % src).read().split()[0] +md5sum2 = os.popen("/usr/bin/md5sum %(file)s 2> /dev/null || /sbin/md5 -q %(file)s" % {"file": src}).read().split()[0] if md5sum != md5sum2: os.system("cp %s %s" % (src, dest)) diff --git a/library/setup b/library/setup index f780be118e5..4d1ac6d3b24 100755 --- a/library/setup +++ b/library/setup @@ -345,7 +345,7 @@ md5sum = None if not os.path.exists(ansible_file): changed = True else: - md5sum = os.popen("md5sum %s" % ansible_file).read().split()[0] + md5sum = os.popen("/usr/bin/md5sum %(file)s 2> /dev/null || /sbin/md5 -q %(file)s" % {"file": ansible_file}).read().split()[0] # Get some basic facts in case facter or ohai are not installed for (k, v) in ansible_facts().items(): @@ -394,7 +394,7 @@ reformat = json.dumps(setup_options, sort_keys=True, indent=4) f.write(reformat) f.close() -md5sum2 = os.popen("md5sum %s" % ansible_file).read().split()[0] +md5sum2 = os.popen("/usr/bin/md5sum %(file)s 2> /dev/null || /sbin/md5 -q %(file)s" % {"file": ansible_file}).read().split()[0] if md5sum != md5sum2: changed = True From eda543f4a596ad895356fa715ac0a7f74110f302 Mon Sep 17 00:00:00 2001 From: Fred Alger Date: Fri, 15 Jun 2012 00:13:35 -0400 Subject: [PATCH 2/2] Remove unused md5sum function from file module --- library/file | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/file b/library/file index daf8715ccf2..892696dd156 100755 --- a/library/file +++ b/library/file @@ -180,9 +180,6 @@ changed = False # =========================================== # support functions -def md5sum(filename): - return os.popen("/usr/bin/md5sum %s" % f).read() - def user_and_group(filename): st = os.stat(filename) uid = st.st_uid