Check file exists and create a symlink

守給你的承諾、 提交于 2019-12-20 10:37:03

问题


I want to do something like that:

if file A exists or there is no symlink B, I want to create a symlink B -> A.

For now I have:

 B:
   file:
    - symlink:
       - target: A
    - exists:
        - name: A

But this is bad it checks not the thing I want. How can I achive this simple thing in salt ?


回答1:


We can use file.directory_exists

{% if not salt['file.directory_exists' ]('/symlink/path/A') %}
symlink:
  file.symlink:
    - name: /path/to/A
    - target: /symlink/path/A
{% endif %}



回答2:


You should use Dan Garthwaite's excellent answer here as a basis for how to check for the existence of a file. I have modified his solution to answer your question.

{% if 1 == salt['cmd.retcode']('test -f /path/to/A') %}
/path/to/A:
  file.symlink:
    - target: /symlink/path/A
{% endif %}


来源:https://stackoverflow.com/questions/22673022/check-file-exists-and-create-a-symlink

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