我正在检查几个配置文件,如果有任何配置文件没有合适的消息,我想停止执行该脚本。
我尝试使用cmd.run打印消息,然后退出,但这对我不起作用
SALTSTACK:
{% if not that config is present %}
cmd.run:
- name:
echo SUITABLE MESSAGE
exit发布于 2016-08-07 05:37:26
这就是Failhard option for salt。如果将其用作全局选项,则状态内的任何故障都将终止以下所有状态的执行。但您也可以有选择地使用它。
也许您可以将Failhard选项添加到现有状态。
如果您希望获得特定的错误消息,示例的1:1翻译可能如下所示:
SALTSTACK:
cmd.run:
- name: bash -c test -e /tmp/notexist || (echo "unable to find file" && exit 1)
- failhard: True它将产生类似如下的输出。错误消息在末尾。
local:
----------
ID: SALTSTACK
Function: cmd.run
Name: bash -c test -e /tmp/notexist || (echo "unable to find file" && exit 1)
Result: False
Comment: Command "bash -c test -e /tmp/notexist || (echo "unable to find file" && exit 1)" run
Started: 21:30:34.473132
Duration: 7.353 ms
Changes:
----------
pid:
5499
retcode:
1
stderr:
stdout:
unable to find file发布于 2016-08-02 02:23:47
你为什么要以这种方式退出。当任何一个状态失败时,执行都将停止。您可以使用file.exists状态来检查特定的配置文件是否存在。如果不是,则状态将失败。检查salt文件状态:file.exists。
https://stackoverflow.com/questions/38628987
复制相似问题