【发布时间】:2018-04-27 08:52:17
【问题描述】:
我使用 Saltstack 管理我们工作站的安装。 在我在客户端上安装 ipa-client-automount 的配方中,我需要:
- 根据 fqdn 设置位置
- 检查 ipa-client-automount 是否已配置
目前,我的状态如下:
ipa-client-automount:
cmd.run:
{% if salt['cmd.run']('hostname -f | grep domain1') %}
- name: ipa-client-automount --location=linkedtodomain1 -U
{% elif salt['cmd.run']('hostname -f | grep domain2') %}
- name: ipa-client-automount --location=linkedtodomain2 -U
{% endif %}
- unless: python -c "from ipapython import sysrestore; from ipaplatform.paths import paths; statestore = sysrestore.StateFile(paths.IPA_CLIENT_SYSRESTORE); exit(not statestore.has_state('autofs'))"
问题是在添加 if 和 elif 语句时,它没有考虑除非。它直接运行命令而不检查除非条件。 另外,我确信我的除非语句有效,只有一个位置就可以了。
我怎样才能写这个让 if 和 unless 同时工作? 谢谢
【问题讨论】:
-
你试过类似
- unless: false的东西吗? -
你也可以试试
onlyif -
我试过
- unless: false,它仍然运行命令。
标签: salt-stack