Reputation: 12930
Could someone let me know how to create a relative symlink.
I have files under following folder.
/usr/share/aws/hive/encryption/test-1.2.3.jar
And I was to create link in this folder which points to this jar. something like
test.jar -> test-1.2.3.jar
However with following ansible code, it takes absolute path.
- name: create soft link
file:
src: "/usr/share/aws/hive/encryption/test-1.2.3.jar"
dest: "/usr/share/aws/hive/encryption/test.jar"
state: link
force: yes
outout
test.jar -> /usr/share/aws/hive/encryption/test-1.2.3.jar
Upvotes: 0
Views: 1132
Reputation: 68294
Try this
- name: create soft link
file:
src: test-1.2.3.jar
path: /usr/share/aws/hive/encryption/test.jar
state: link
force: true
Quoting from the parameter src:
Relative paths are relative to the file being created (path) which is how the Unix command ln -s SRC DEST treats relative paths.
Note: The parameter force is needed when:
Unfortunately, the wording in the docs is misleading:
Force the creation of the symlinks in two cases: the source file does not exist (but will appear later); the destination exists and is a file (so, we need to unlink the path file and create symlink to the src file in place of it).
Upvotes: 4
Reputation: 3691
you can try the shell module instead. In your case, if is taking the absolute path, because thats how source and destination are given.
- name: Create a Symlink
shell:
cmd: ln -s test-1.2.3.jar test.jar
chdir: /usr/share/aws/hive/encryption/
Upvotes: 1