Check file exists and create a symlink

Darek picture Darek · Mar 26, 2014 · Viewed 20.4k times · Source

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 ?

Answer

Abhilash Joseph picture Abhilash Joseph · May 26, 2015

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 %}