Situation with relative symlinks (file state=link)

Hello,

I just figured Ansible doesn’t allow to create a symlink pointing to a relative file. Specifically,

file: state=link src=…/settings_prod.py dest=~/frontend/settings_prod.py

Gives msg: absolute paths are required.

Quick googling led to https://github.com/ansible/ansible/pull/281 which talks about fixing relative symlinks support, but looking at the patch, it instead tries to convert relative symlink into absolute. And then there’s https://github.com/ansible/ansible/issues/815 which just deletes relative-handling code.

But the idea about symlinks is that they may contain arbitrary paths - including not (yet) existing. And relative symlink’s path is resolved against its anchor. So both of:

shell: ln -s …/foo/bar /tmp/link
python: os.symlink(“…/foo/bar”, “/tmp/link”)

Create a symlink named /tmp/link, pointing to …/foo/bar. The latter is resolved against link’s own location (thus in this specific case it will point to /foo/bar , but it can be moved and will point to a relative file still). Also, …/foo/bar doesn’t have to exist at the time of link creation.

All this behavior is mandated by POSIX: http://pubs.opengroup.org/onlinepubs/009695399/functions/symlink.html (Open Group Base Specifications is openly available superset of POSIX).

So, what about:

Don’t do anything to src= param to file state=link and just use it as is to create a symlink, to comply with OS behavior?

Please file a github ticket and we can look into this.

Thanks, done: https://github.com/ansible/ansible/issues/4459