【问题标题】:check if file exists in salt file system salt://检查文件是否存在于 salt 文件系统 salt://
【发布时间】:2018-04-20 09:52:23
【问题描述】:

我想检查 salt 文件系统 (salt://) 中是否存在文件,并根据该文件添加指令。 我确切地说我使用 gitfs 作为 salt 文件系统中的挂载点,并且不使用 /srv 目录。

所以更具体地说,我想做这样的事情:

{% if salt['file.directory_exists']('salt://a_directory') %}
 file.recurse:
    - name: dest
    - source: salt://a_directory
    - template: jinja
{% endif %}

但它似乎不起作用。

【问题讨论】:

    标签: salt-stack


    【解决方案1】:

    我想为 pkg.installed 加载带有包列表的 yaml 文件,但前提是 yaml 在主服务器上(文件名由变量构造)。

    我正在使用salt.modules.cp.list_master

    # Search path on the master:
    {% set found = salt.cp.list_master(prefix='my/path/example.yaml') | count %}
    {% if found %}
    
    {# Do something… #}
    
    {% endif %}
    

    如果你想检查一个目录,你可以使用这个:

    {% set found = salt.cp.list_master_dirs(prefix='my/path') | count %}

    【讨论】:

      猜你喜欢
      • 2012-08-16
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多