小编Jia*_*Han的帖子

如何为同一源下的文件夹/文件创建多个符号链接

我想创建文件夹:temp2,它​​能够存储其他饲料的子文件夹/文件的所有符号链接:temp1。with_items可以帮助完成此任务,但它需要列出所有文件夹/文件名,如下所示:

- name: "create folder: temp2 to store symlinks"
  file:
    path: "/etc/temp2"
    state: directory

- name: "create symlinks & store in temp2"
  file:
    src: "/etc/temp1/{{ item.src }}"
    dest: "/etc/temp2/{{ item.dest }}"
    state: link
    force: yes
  with_items:
    - { src: 'BEAM', dest: 'BEAM' }
    - { src: 'cfg', dest: 'cfg' }
    - { src: 'Core', dest: 'Core' }
    - { src: 'Data', dest: 'Data' }
Run Code Online (Sandbox Code Playgroud)

它不灵活,因为将添加或删除 temp1 下的子文件夹/文件,我需要经常更新上述脚本以保持符号链接的更新

有没有办法自动检测 temp1 下的所有文件/文件夹而不是维护with_items列表?

symlink ansible

4
推荐指数
2
解决办法
3634
查看次数

标签 统计

ansible ×1

symlink ×1