mizmu
mizmu

Reputation: 111

Saltstack: ignoring result of cmd.run

I am trying to invoke a command on provisioning via Saltstack. If command fails then I get state failing and I don't want that (retcode of command doesn't matter).

Currently I have the following workaround:

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

is there any way to make such state ignore retcode using salt features? or maybe I can exclude this state from logs?

Upvotes: 10

Views: 6654

Answers (2)

Bridger
Bridger

Reputation: 61

If you don't care what the result of the command is, you can use:

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

This was tested in Salt 2017.7.0 but would probably work in earlier versions.

Upvotes: 5

oeuftete
oeuftete

Reputation: 2718

Use check_cmd :

fails:
  cmd.run:
    - name: /bin/false

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

Output:

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

Upvotes: 12

Related Questions