ansible/ansible — pull request #3830 by simonsd (2013-08-13 10:56:21+00:00)
Title: file: state=hard only works for initial setup of hardlink

The new state=hard (indicating a hardlink rather than symlink) only works the first time around.
Every time this action is run after that it will fail because it thinks that the hardlink is just a file.
I think the problem lies with the os.readlink(path) part in the below snippet.

Snippet

elif prev_state == 'link':
old_src = os.readlink(path)
if not os.path.isabs(old_src):
old_src = os.path.join(os.path.dirname(path), old_src)
if old_src != src:
if module.check_mode:
module.exit_json(changed=True)
os.unlink(path)
dolink(src, path, state, module)
changed = True

This snippet is from library/files/file on current devel branch (3e32654f9d67a1a7b5109fe9c543f89401f71746 at writing)

Running this I get

OSError: [Errno 22] Invalid argument: '/path/to/file'