saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.15k stars 5.48k forks source link

[TECH DEBT] Micosoft has declared deprecation of wmic, replaced by Powershell for WMI #66959

Open qlik-okl opened 1 week ago

qlik-okl commented 1 week ago

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

welcome[bot] commented 1 week ago

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:

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 saltproject@vmware.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

qlik-okl commented 6 days ago

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)

twangboy commented 5 days ago

Since we're using PowerShell anyway I decided to use Get-PhysicalDisk instead.