summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam DeConinck <ajdecon@ajdecon.org>2016-02-23 13:47:51 -0700
committerJames Cammarata <jimi@sngx.net>2017-05-18 02:32:02 -0500
commitc5067cff6b2bff42e0d34408ab339c79939be545 (patch)
treed1ab757b64ddb3c17a286e3cf6e45c7f7dcc9b58
parent180ce9ffe679a565fbfc69b1cfddcb5d97141b87 (diff)
downloadansible-c5067cff6b2bff42e0d34408ab339c79939be545.tar.gz
Fix for ansible/ansible-modules-core#1568
When checksums of local and remote files match, and when follow = True, determine if remote destination is a symlink. If so, de-reference it and pass the link target to the file module as 'dest'. This change fixes an edge case in file copy behavior when: - 'dest' is a symlink to some other file ('realdest') - follow = True - the checksums of the source file, 'src', and the symlink target, 'realdest', match. Because the checksums match, the copy module is skipped and the file module is invoked directly with 'dest' = the symlink, and 'src' = the source of the copy module, whether that source is present on the target machine or not. When 'src' doesn't exist on the target machine, this leads to an error that looks like this because it can't change the target of the symlink: TASK [copy] ******************************************************************** fatal: [192.168.56.101]: FAILED! => {"changed": false, "checksum": "f572d396fae9206628714fb2ce00f72e94f2258f", "failed": true, "gid": 1000, "group": "ajdecon", "mode": "0777", "msg": "src file does not exist, use \"force=yes\" if you really want to create the link: /tmp/issue1568/dest_dir/source", "owner": "ajdecon", "path": "/tmp/issue1568/dest_dir/dest", "size": 8, "src": "source", "state": "link", "uid": 1000} When the path 'src' *does* exist on the target machine, the file module makes this the symlink "dest -> src" instead of "dest -> realdest"... even if the checksum of 'src' on the target machine is different from the checksum of 'src' on the machine where Ansible is running. (cherry picked from commit 2f74f6738d2e147fa1642924220d749de7ebedad)
-rw-r--r--lib/ansible/plugins/action/copy.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/ansible/plugins/action/copy.py b/lib/ansible/plugins/action/copy.py
index 9133dcf0be..dda2bb759e 100644
--- a/lib/ansible/plugins/action/copy.py
+++ b/lib/ansible/plugins/action/copy.py
@@ -271,6 +271,14 @@ class ActionModule(ActionBase):
self._remove_tmp_path(tmp)
continue
+ # Fix for https://github.com/ansible/ansible-modules-core/issues/1568.
+ # If checksums match, and follow = True, find out if 'dest' is a link. If so,
+ # change it to point to the source of the link.
+ if follow:
+ dest_status_nofollow = self._execute_remote_stat(dest_file, all_vars=task_vars, follow=False)
+ if dest_status_nofollow['islnk'] and 'lnk_source' in dest_status_nofollow.keys():
+ dest = dest_status_nofollow['lnk_source']
+
# Build temporary module_args.
new_module_args = self._task.args.copy()
new_module_args.update(