diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 268371dea1..45d0ec6ae7 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -511,7 +511,7 @@ class Runner(object): def _remote_md5(self, conn, tmp, path): ''' takes a remote md5sum without requiring python, and returns 0 if no file ''' - test = "rc=0; [ -r \"%s\" ] || rc=2; [ -f \"%s\" ] || rc=1" % (path,path) + test = "rc=0; [ -r \"%s\" ] || rc=2; [ -f \"%s\" ] || rc=1; [ -d \"%s\" ] && rc=3" % (path, path, path) md5s = [ "(/usr/bin/md5sum %s 2>/dev/null)" % path, # Linux "(/sbin/md5sum -q %s 2>/dev/null)" % path, # ? diff --git a/lib/ansible/runner/action_plugins/copy.py b/lib/ansible/runner/action_plugins/copy.py index f3625724fc..4eacd42e2d 100644 --- a/lib/ansible/runner/action_plugins/copy.py +++ b/lib/ansible/runner/action_plugins/copy.py @@ -34,10 +34,6 @@ class ActionModule(object): source = options.get('src', None) dest = options.get('dest', None) - if dest.endswith("/"): - base = os.path.basename(source) - dest = os.path.join(dest, base) - if (source is None and not 'first_available_file' in inject) or dest is None: result=dict(failed=True, msg="src and dest are required") return ReturnData(conn=conn, result=result) @@ -65,7 +61,15 @@ class ActionModule(object): result=dict(failed=True, msg="could not find src=%s" % source) return ReturnData(conn=conn, result=result) + if dest.endswith("/"): + base = os.path.basename(source) + dest = os.path.join(dest, base) + remote_md5 = self.runner._remote_md5(conn, tmp, dest) + if remote_md5 == '3': + # Destination is a directory + dest = os.path.join(dest, os.path.basename(source)) + remote_md5 = self.runner._remote_md5(conn, tmp, dest) exec_rc = None if local_md5 != remote_md5: