saltstack / saltstack/salt

[BUG] cmd.run: "- prepend_path:" broken (fails with KeyError exception) on Windows

Open
#57,672 2 comments 0 reactions 1 assignee View on GitHub

@dwoz is already working on this.

Since Jun 25, 2020.

bug Execution-Module severity-high Windows
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
Due to #56199 I changed some states using cmd.run from

- env:
  - PATH: ...

to

- prepend_path: ...

but that also led to failures on (Windows) minions running Salt Minion 3000.3.

I even get two different error outputs for the same kind of thing (running in a loop):

----------
          ID: something_one
    Function: cmd.run
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "c:\salt\bin\lib\site-packages\salt-3000.3-py3.5.egg\salt\state.py", line 1981, in call
                  **cdata['kwargs'])
                File "c:\salt\bin\lib\site-packages\salt-3000.3-py3.5.egg\salt\loader.py", line 1977, in wrapper
                  return f(*args, **kwargs)
                File "c:\salt\bin\lib\site-packages\salt-3000.3-py3.5.egg\salt\states\cmd.py", line 892, in run
                  cret = mod_run_check(cmd_kwargs, onlyif, unless, creates)
                File "c:\salt\bin\lib\site-packages\salt-3000.3-py3.5.egg\salt\states\cmd.py", line 366, in mod_run_check
                  cmd = __salt__['cmd.retcode'](unless, ignore_retcode=True, python_shell=True, **cmd_kwargs)
                File "c:\salt\bin\lib\site-packages\salt-3000.3-py3.5.egg\salt\modules\cmdmod.py", line 2277, in retcode
                  **kwargs)
                File "c:\salt\bin\lib\site-packages\salt-3000.3-py3.5.egg\salt\modules\cmdmod.py", line 598, in _run
                  run_env['PATH'] = ':'.join((prepend_path, run_env['PATH']))
              KeyError: 'PATH'
     Started: 14:23:09.012359
    Duration: 62.504 ms
     Changes:

and

----------
          ID: something_two
    Function: cmd.run
      Result: False
     Comment: 'PATH'
     Started: 14:24:12.652165
    Duration: 15.624 ms
     Changes:

The reason for this seems to be the code for prepend_path in cmdmod.py, which looks like being Linux/Unix only (https://github.com/saltstack/salt/blob/master/salt/modules/cmdmod.py#L619). It

  1. uses a variable name of "PATH", but all Windows systems I looked at use "Path" and the environment variable code seems to be case-sensitive (now?)
  2. always uses ":" as path separator, but Windows requires ";"

Setup
Salt Minion 3000.3

Steps to Reproduce the behavior
Execute any cmd.run: state containing - prepend_path: on a Windows Minion running 3000.3

Expected behavior
It should not fail.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.