# Situation with relative symlinks (file state=link)

**URL:** <https://forum.ansible.com/t/situation-with-relative-symlinks-file-state-link/13640>\
**Category:** Ansible Project\
**Created:** [October 9, 2013, 11:28am UTC](https://forum.ansible.com/t/situation-with-relative-symlinks-file-state-link/13640 "2013-10-09T11:28:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Sokolovsky](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@Paul\_Sokolovsky](https://forum.ansible.com/u/Paul_Sokolovsky)\
**Post date:** [October 9, 2013, 11:28am UTC](https://forum.ansible.com/t/situation-with-relative-symlinks-file-state-link/13640/1 "2013-10-09T11:28:35Z")

</div>

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](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](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](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?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 9, 2013, 2:19pm UTC](https://forum.ansible.com/t/situation-with-relative-symlinks-file-state-link/13640/2 "2013-10-09T14:19:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul\_Sokolovsky](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@Paul\_Sokolovsky](https://forum.ansible.com/u/Paul_Sokolovsky)\
**Post date:** [October 11, 2013, 4:57pm UTC](https://forum.ansible.com/t/situation-with-relative-symlinks-file-state-link/13640/3 "2013-10-11T16:57:18Z")

</div>

Thanks, done: [https://github.com/ansible/ansible/issues/4459](https://github.com/ansible/ansible/issues/4459)
