Ansible:创建一个相对符号链接 [英] Ansible : create a relative symlink

查看:34
本文介绍了Ansible:创建一个相对符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的剧本中,我需要为一个仓库创建一个符号链接.

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

使用命令(shell),它可能像这样工作:

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']

-> 像这样,我的符号链接是直接在 i99 存储库/

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

SYMLINK -> SOURCE_FOLDER

但是在使用 Ansible 文件模块时,像这样:

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']

我的输出是这样的:

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

我该怎么做?

推荐答案

简单:

- 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 将接受绝对、相对和不存在的路径.相对路径不展开.

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

这篇关于Ansible:创建一个相对符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆