Ansible : create a relative symlink

孤街浪徒 提交于 2020-07-31 16:02:46

问题


In my playbook, I need to create a symbolic link for a repo.

With command (shell) it may work like this:

########## Create symbolic link 
- name: Create symbolic link 
  shell : ln   -s  "{{SOURCE_FOLDER}}"  SYMLINK
  args :
    chdir : "/opt/application/i99/"
  when:
    - ansible_host in groups['ihm']

-> like this my symbolic link is created directly inside i99 repo /

SYMLINK -> SOURCE_FOLDER

But while doing it with the Ansible file module, like this:

########## Create symbolic link 
- name: Create symbolic link 
  file:
   src: "/opt/application/i99/{{SOURCE_FOLDER}}/"
   dest: "/opt/application/i99/SYMLINK"
   state: link
  when:
    - ansible_host in groups['ihm']

My output is this :

SYMLINK -> /opt/application/i99/SOURCE_FOLDER

As I don't want that it points to the whole path, and I need to obtain the first format:

SYMLINK -> SOURCE_FOLDER

How can I do it?


回答1:


Simply:

- name: Create symbolic link 
  file:
    src: "{{SOURCE_FOLDER}}"
    dest: "/opt/application/i99/SYMLINK"
    state: link

As you can see in the manual for the file module:

src  Will accept absolute, relative and nonexisting paths. Relative paths are not expanded.



来源:https://stackoverflow.com/questions/48560311/ansible-create-a-relative-symlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!