Search code examples
windowsdevopssalt-project

Saltstack - win_path doesn't modify system PATH variable as expected


I've defined a following .sls state file:

npm:
  chocolatey.installed:
    - name: nodejs
    - version: 16.19.1

'C:\Program Files\nodejs':
  win_path.exists

After I apply state above, running sudo salt 'minion_name' win_path.get_path shows me that the path was added:

minion_name:
    - C:\Program Files\nodejs
    - %SystemRoot%\system32
    - %SystemRoot%
    - %SystemRoot%\System32\Wbem
    - %SYSTEMROOT%\System32\WindowsPowerShell\v1.0
    - %SYSTEMROOT%\System32\OpenSSH
    - C:\Program Files\Amazon\cfn-bootstrap
    - C:\Program Files\Salt Project\Salt
    - C:\ProgramData\chocolatey\bin

But when I run sudo salt 'minion_name' cmd.run "echo %PATH%" (or log into the Windows machine and run "echo %PATH%" there), the content of the variable is completely different:

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Amazon\cfn-bootstrap\;C:\Program Files\Salt Project\Salt;C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps

Am I missing something? Or is this a bug with salt.modules.win_path? Running node --version returns 'node' is not recognized as an internal or external command, operable program or batch file. Also I'm sure that the path to nodejs executables is correct, I checked it after chocolatey installed the module.


Solution

  • Environment changes are not picked up by running processes (including cmd shells and the salt-minion service) or their children.

    To ensure a system variable change can be seen by everything, a reboot is required.