Saltstack中if语句的正确语法

时间:2019-07-17 21:16:28

标签: salt-stack

运行以下命令: # TOP_LEVEL_COMMENT name: hydrated-cluster subcomponents: # top_comment - data: elasticsearch-fluentd-kibana # inline comment 我会成真, 我喜欢将其添加到我的状态,但是找不到正确的语法。

salt host1 file.check_perms /xxx/zzz '{}' root sudo 0750

跟踪:

{% if not salt['file.check_perms']('/xxx/zzz/', '{}',['root'],['sudo'],['0750']) %
Set group ownership and permissions:
  file.directory:
    - name: /xxx/zzz/
    - user: root
    - group: sudo
    - dir_mode: 750
    - file_mode: 750
    - recurse:
      - user
      - group
      - mode
{% endif %}

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我自己找到了解决方案,以下语法可行:

{% if salt['file.check_perms']('/xxx/zzz/', {},('root'),('sudo'),('0750')) != 'True' %} 
Set group ownership and permissions:
  file.directory:
    - name: /zzz/zzz/
    - user: root
    - group: sudo
    - dir_mode: 750
    - file_mode: 750
    - recurse:
      - user
      - group
      - mode
{% endif %}