2016-07-28 28 views
0

我正在檢查幾個配置文件,並且如果任何配置文件不適用於合適的消息,我想停止執行該腳本。Salt Stack:拖延執行

我想cmd.run打印的消息,並退出但是這不是爲我工作

SALTSTACK: 
    {% if not that config is present %} 
    cmd.run: 
     - name: 
      echo SUITABLE MESSAGE 
      exit 

回答

0

你爲什麼要以這種方式退出。 當任何狀態失敗時,執行將停止。 您可以使用file.exists狀態來檢查特定配置文件是否存在。如果不是,狀態將會失敗。檢查鹽文件狀態:file.exists

0

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