[TECH DEBT] Micosoft has declared deprecation of wmic, replaced by Powershell for WMI
Description of the tech debt to be addressed, include links and screenshots
As detailed in https://techcommunity.microsoft.com/t5/windows-it-pro-blog/wmi-command-line-wmic-utility-deprecation-next-steps/ba-p/4039242 wmic is going away, and is actually removed by default in latest versions of for example Windows 11. This results in errors like
Traceback (most recent call last):
File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\loader\__init__.py", line 1188, in grains
ret = funcs[key](**kwargs)
File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\loader\lazy.py", line 160, in __call__
ret = self.loader.run(run_func, *args, **kwargs)
File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\loader\lazy.py", line 1269, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\loader\lazy.py", line 1284, in _run_as
return _func_or_method(*args, **kwargs)
File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\grains\disks.py", line 33, in disks
return _windows_disks()
File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\grains\disks.py", line 164, in _windows_disks
cmdret = __salt__["cmd.run_all"](
File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\modules\cmdmod.py", line 1014, in _run_all_quiet
return _run(
File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\modules\cmdmod.py", line 753, in _run
raise CommandExecutionError(msg)
salt.exceptions.CommandExecutionError: Unable to run command 'REDACTED' with the context '{...}, 'stdin': None, 'stdout': -1, 'stderr': -1, 'with_communicate': True, 'timeout': None, 'bg': False}', reason: [WinError 2] The system cannot find the file specified
Saltstack needs to replace wmic dependency and use one of the proposed replacements in the article linked above.
Versions Report
Minion salt-call --version salt-call 3007.1 (Chlorine) Master also running 3007.1
Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey. Please be sure to review our Code of Conduct. Also, check out some of our community resources including:
- Community Wiki
- Salt’s Contributor Guide
- Join our Community Slack
- IRC on LiberaChat
- Salt Project YouTube channel
- Salt Project Twitch channel
There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!
The wmic command used in https://github.com/saltstack/salt/blob/221420cd5719c3f201a3114310a93c167b9e52e3/salt/grains/disks.py#L155 can be replaced by a corresponding powershell command like this
Get-CimInstance -Namespace root/Microsoft/Windows/Storage -query 'select * from MSFT_PhysicalDisk' | ft DeviceID,MediaType
Giving its output in identical format as the old wmic command.
(Tested on a Windows 11 24H2 box)
Since we're using PowerShell anyway I decided to use Get-PhysicalDisk instead.
Hi, when will this be fixed in the lastet version 3007.1 to download?
I tried the latest version 3007.1 today with a fresh Windows 11 24h2 OS and get the same error.
Description of the tech debt to be addressed, include links and screenshots
As detailed in https://techcommunity.microsoft.com/t5/windows-it-pro-blog/wmi-command-line-wmic-utility-deprecation-next-steps/ba-p/4039242 wmic is going away, and is actually removed by default in latest versions of for example Windows 11. This results in errors like
Traceback (most recent call last): File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\loader\__init__.py", line 1188, in grains ret = funcs[key](**kwargs) File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\loader\lazy.py", line 160, in __call__ ret = self.loader.run(run_func, *args, **kwargs) File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\loader\lazy.py", line 1269, in run return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs) File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\loader\lazy.py", line 1284, in _run_as return _func_or_method(*args, **kwargs) File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\grains\disks.py", line 33, in disks return _windows_disks() File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\grains\disks.py", line 164, in _windows_disks cmdret = __salt__["cmd.run_all"]( File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\modules\cmdmod.py", line 1014, in _run_all_quiet return _run( File "C:\Program Files\Salt Project\Salt\Lib\site-packages\salt\modules\cmdmod.py", line 753, in _run raise CommandExecutionError(msg) salt.exceptions.CommandExecutionError: Unable to run command 'REDACTED' with the context '{...}, 'stdin': None, 'stdout': -1, 'stderr': -1, 'with_communicate': True, 'timeout': None, 'bg': False}', reason: [WinError 2] The system cannot find the file specifiedSaltstack needs to replace wmic dependency and use one of the proposed replacements in the article linked above.
Versions Report
Minion salt-call --version salt-call 3007.1 (Chlorine) Master also running 3007.1
I'm also running into this issue. Any way to circumvent these errors in the meantime?
You could put the files from the above PR on the Fileserver and have the Salt master sync those down. Those would supersede the local versions. You'd just need to remember to remove those after you install a version with the fix. https://saltstack.github.io/docs-saltproject-io/en/latest/topics/development/modules/index.html#the-salt-file-server
_grains/disks.py
_grains/iscsi.py
_modules/cmdmod.py
_utils/path.py
You would need to pull these from the 3006.x branch for the 3006.9 minions. There's currently a merge forward PR that brings these changes to the 3007.x branch. Once that's merged, you could use those files for 3007.1.