Defining states depending on existance of a file/directory

自作多情 提交于 2019-11-30 22:24:35

You can use unless for this.

dummy:
  file.touch:
    - name: /tmp/dummy/tmp.txt
    - unless: test -d /tmp/dummy/
{% if 1 == salt['cmd.retcode']('test -f /tmp/woo.test') %}
ack:
  file.touch:
    - name: /tmp/woo.test
{% endif %}

You could use the pure python renderer for salt. Here is how it would look like.

#!py
import os

def run():
  # defines the hash config
  config = {}

  if (not os.path.isfile("/tmp/dummy")):
    config["dummy"] = { 
      "file.touch": [
        {'name': '/tmp/dummy'},
      ],  
    }    

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