我正在尝试通过Saltstack调配命令。如果命令失败,那么我将获得状态失败,并且我不希望这样做(命令的重新编码无关紧要)。
目前,我有以下解决方法:
Run something:
cmd.run:
- name: command_which_can_fail || true
有什么方法可以使用Salt功能使这种状态忽略retcode?或者也许我可以从日志中排除此状态?
最佳答案
使用 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
关于salt-stack - Saltstack : ignoring result of cmd.运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27917557/