summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2017-05-10 17:11:11 -0700
committerToshio Kuratomi <a.badger@gmail.com>2017-05-11 20:37:31 -0700
commit548cacdf6a28a708142c4a2e4ed1ecba8102b60a (patch)
tree078d00cd941118a1add6a22a1f10d152944b7530
parent16325f6f150ec09e7ca5618a9c802513bb3302a6 (diff)
downloadansible-548cacdf6a28a708142c4a2e4ed1ecba8102b60a.tar.gz
Fix template not showing a diff with a directory
Template can take a directory as the destination. When that's the case, we need to diff between the source and the file inside of the directory. That happened when the directory was specified with a trailing slash but not when it was specified on its own. This change fixes that. Fixes #24413
-rw-r--r--lib/ansible/plugins/action/template.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/ansible/plugins/action/template.py b/lib/ansible/plugins/action/template.py
index 6cad672f9e..35bc8d4ce2 100644
--- a/lib/ansible/plugins/action/template.py
+++ b/lib/ansible/plugins/action/template.py
@@ -97,9 +97,14 @@ class ActionModule(ActionBase):
directory_prepended = False
if dest.endswith(os.sep):
+ # Optimization. trailing slash means we know it's a directory
directory_prepended = True
- base = os.path.basename(source)
- dest = os.path.join(dest, base)
+ dest = self._connection._shell.join_path(dest, os.path.basename(source))
+ else:
+ # Find out if it's a directory
+ dest_stat = self._execute_remote_stat(dest, task_vars, True, tmp=tmp)
+ if dest_stat['exists'] and dest_stat['isdir']:
+ dest = self._connection._shell.join_path(dest, os.path.basename(source))
# template the source data locally & get ready to transfer
b_source = to_bytes(source)