Search code examples
salt-project

Defining states depending on existance of a file/directory


How is it possible to get something like the following running:

{% if not exist('/tmp/dummy/') then %}
dummy:
  file.touch:
    - name: /tmp/dummy/tmp.txt

...
{% endif %}

I need it for installing software from a ZIP-file. I want to unzip on the minions, but there I don't want to have any remnants of licence files, which I only need for installation, left.


Solution

  • You can use unless for this.

    dummy:
      file.touch:
        - name: /tmp/dummy/tmp.txt
        - unless: test -d /tmp/dummy/