Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saltstack: ignoring result of cmd.run

Tags:

salt-stack

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?

like image 541
mizmu Avatar asked Jan 13 '15 08:01

mizmu


2 Answers

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
like image 97
oeuftete Avatar answered Nov 17 '22 16:11

oeuftete


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.

like image 5
Bridger Avatar answered Nov 17 '22 16:11

Bridger