【问题标题】:Saltstack: ignoring result of cmd.runSaltstack:忽略 cmd.run 的结果
【发布时间】:2015-03-11 03:19:09
【问题描述】:

我正在尝试通过 Saltstack 调用配置命令。如果命令失败,那么我会得到状态失败,我不希望这样(命令的重新编码无关紧要)。

目前我有以下解决方法:

Run something:
  cmd.run:
    - name: command_which_can_fail || true

有没有办法让这种状态忽略使用盐功能的重新编码?或者我可以从日志中排除这种状态?

【问题讨论】:

    标签: salt-stack


    【解决方案1】:

    使用check_cmd

    fails:
      cmd.run:
        - name: /bin/false
    
    succeeds:
      cmd.run:
        - name: /bin/false
        - check_cmd:
          - /bin/true
    

    输出:

    local:
    ----------
              ID: fails
        Function: cmd.run
            Name: /bin/false
          Result: False
         Comment: Command "/bin/false" run
         Started: 16:04:40.189840
        Duration: 7.347 ms
         Changes:
                  ----------
                  pid:
                      4021
                  retcode:
                      1
                  stderr:
    
                  stdout:
    
    ----------
              ID: succeeds
        Function: cmd.run
            Name: /bin/false
          Result: True
         Comment: check_cmd determined the state succeeded
         Started: 16:04:40.197672
        Duration: 13.293 ms
         Changes:
                  ----------
                  pid:
                      4022
                  retcode:
                      1
                  stderr:
    
                  stdout:
    
    
    Summary
    ------------
    Succeeded: 1 (changed=2)
    Failed:    1
    ------------
    Total states run:     2
    

    【讨论】:

    【解决方案2】:

    如果你不关心命令的结果是什么,你可以使用:

    Run something:
     cmd.run:
        - name: command_which_can_fail; exit 0
    

    这已在 Salt 2017.7.0 中进行了测试,但可能适用于早期版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-27
      • 1970-01-01
      • 2015-07-25
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 2021-05-16
      • 1970-01-01
      相关资源
      最近更新 更多