0

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 
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137
  • 1
    check this out https://stackoverflow.com/questions/48560311/ansible-create-a-relative-symlink – Venu S Jul 06 '20 at 19:56

2 Answers2

3

Try this


  - name: create soft link
    file:
        src: "test-1.2.3.jar"
        path: "/usr/share/aws/hive/encryption/test.jar"
        state: link
        force: yes

Quoting from 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.

Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
1

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/
Venu S
  • 3,251
  • 1
  • 9
  • 25