From 84fb9f032d06d0b52b18ee519dc2050adee1d053 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 17 Jul 2017 12:06:35 -0700 Subject: [PATCH] Fix symlink handling (#26877) * Fix symlink handling On symlinks, make lnk_source return the absolute path of the target of the symlink. Add a new return field lnk_target that returns the actual, unexpanded path to the target of the symlink. --- lib/ansible/modules/files/stat.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/files/stat.py b/lib/ansible/modules/files/stat.py index 3133272329..facba7e6c9 100644 --- a/lib/ansible/modules/files/stat.py +++ b/lib/ansible/modules/files/stat.py @@ -292,10 +292,16 @@ stat: type: boolean sample: False lnk_source: - description: Original path + description: Target of the symlink normalized for the remote filesystem returned: success, path exists and user can read stats and the path is a symbolic link type: string sample: /home/foobar/21102015-1445431274-908472971 + lnk_target: + description: Target of the symlink. Note that relative paths remain relative + returned: success, path exists and user can read stats and the path is a symbolic link + type: string + sample: ../foobar/21102015-1445431274-908472971 + version_added: 2.4 md5: description: md5 hash of the path returned: success, path exists and user can read stats and path @@ -481,6 +487,7 @@ def main(): # symlink info if output.get('islnk'): output['lnk_source'] = os.path.realpath(b_path) + output['lnk_target'] = os.readlink(b_path) try: # user data pw = pwd.getpwuid(st.st_uid)