我使用Saltstack管理我们工作站的安装。在我在客户端上安装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和elif语句。它直接运行命令,而不检查“除非”条件。而且,我确信我的除非语句是有效的,这一切都很好,只有一个位置。
除非同时工作,否则我怎么写这个才能有if?谢谢
发布于 2017-11-14 13:41:47
我有一个可行的解决方案:
ipa-client-automount:
cmd.run:
- names:
{% if salt['cmd.run']('hostname -f | grep domain1') %}
- ipa-client-automount --location=linkedtodomain1 -U
{% elif salt['cmd.run']('hostname -f | grep domain2') %}
- ipa-client-automount --location=linkedtodomain2 -U
{% endif %}
- unless: condition这不是最干净的解决方案,但对我有效。不知道为什么这在names上不起作用,而在name上起作用。
发布于 2017-11-19 22:07:15
我认为问题在如果情况。如果以这种方式使用if salt['cmd.run'](),则第一个if将始终为真。
在salt中,一种更好的方法是使用host谷物,如下所示:
{% if grains.get('host') == 'domain1' %}或者,如果您真的想使用cmd.run方法,请尝试如下所示:
{% if salt['cmd.run']('hostname -f') == 'domain1' %}https://stackoverflow.com/questions/47285241
复制相似问题