Salt's cmd.run ignoring shell script return code

Offen
#42 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
shell
Bereich
devops

Rechercherichtung

Start with Salt's cmd.run and cmd.script behavior, using the provided SLS block and /u01/orastage/oraclepsu/scripts/oracle_ss_wrapper.ksh as the reproduction. Compare the successful and failing minion results, including stateful output and retcode handling. Done means a nonzero script result is reported as a failed state while the stateful comment and change data remain correct.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

I am using a simple salt state to send (file.managed) and execute (cmd.run) a shell script on a minion/target. No matter what exit or return value the shell script sends, the salt master is interpreting the result as successful.

I tried using cmd.script, but keep getting a permission denied error on the temp version of the file under /tmp. Filesystem is not mounted with noexec so we can't figure out why it won't work. I saw earlier references to a bug for this but was supposedly fixed in 2012.

For cmd.run, stdout in the job output shows the failed return code and message but Salt still says Success. Running the script locally on the minion reports the return/exit code as expected.

I tried adding stateful: True into the cmd.run block and formatted the key value pairs at the end of the shell script as demonstrated in the docs.

Running against 2 minion target, 1 fail 1 succeed. Both report Result as True but correctly populate Comment with my key value pair.

I've tried YES/NO, TRUE/FALSE, 0/1 - nothing works.

The end of my shell script, formatted as shown in the docs.

echo Return_Code=${STATUS}

if [[ ${STATUS} -ne 0 ]]
   then
      echo ""
      echo "changed=False comment='Failed'"
   else
      echo ""
      echo "changed=True comment='Success'"
fi

The SLS block:

stop_oracle:
  cmd.run:
    - name: {{scriptDir}}/{{scriptName}}{{scriptArg}}
    - stateful: True
    - failhard: True

SLS output from Successful minion:

----------
          ID: stop_oracle
    Function: cmd.run
        Name: /u01/orastage/oraclepsu/scripts/oracle_ss_wrapper.ksh stop
      Result: True
     Comment: Success
     Started: 14:37:44.519131
    Duration: 18930.344 ms
     Changes:
              ----------
              changed:
                  True
              pid:
                  26195
              retcode:
                  0
              stderr:
                  stty: standard input: Inappropriate ioctl for device
              stdout:
                  Script running under ROOT

                  Mon Jul  1 14:38:03 EDT 2019 : Successful
                  Return_Code=0

SLS output from Failed minion:

----------
          ID: stop_oracle
    Function: cmd.run
        Name: /u01/orastage/oraclepsu/scripts/oracle_ss_wrapper.ksh stop
      Result: True
     Comment: Failed
     Started: 14:07:14.153940
    Duration: 38116.134 ms
     Changes:

Output from shell script run locally on fail target:

$ /u01/orastage/oraclepsu/scripts/oracle_ss_wrapper.ksh stop

Mon Jul  1 15:29:18 EDT 2019 : There are errors in the process
Return_Code=1

changed=False comment='Failed'

Output from shell script run locally on success target:

$ /u01/orastage/oraclepsu/scripts/oracle_ss_wrapper.ksh stop

Mon Jul  1 16:03:18 EDT 2019 : Successful
Return_Code=0

changed=True comment='Success'

Version Information:

Master: Oracle linux, 2018.3.2 (Oxygen) 
Minion: Redhat Linux, 2017.7.4 (Nitrogen) 
Minion: AIX, 2017.7.2 (Nitrogen) 
Vorherrschende Sprache
Keine Sprachdaten
Sterne
36
Forks
13
Ø Merge
2 Min.
Gemergte PRs (30 T.)
1

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus saltstack/community

Alle Issues in saltstack/community

Ähnliche Issues

Weitere Issues zu DevOps

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.