Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining states depending on existance of a file/directory

Tags:

salt-stack

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.

like image 876
bergwiesel Avatar asked Dec 09 '22 09:12

bergwiesel


2 Answers

You can use unless for this.

dummy:
  file.touch:
    - name: /tmp/dummy/tmp.txt
    - unless: test -d /tmp/dummy/
like image 128
gtmanfred Avatar answered Dec 10 '22 23:12

gtmanfred


{% if 1 == salt['cmd.retcode']('test -f /tmp/woo.test') %}
ack:
  file.touch:
    - name: /tmp/woo.test
{% endif %}
like image 30
Dan Garthwaite Avatar answered Dec 10 '22 22:12

Dan Garthwaite