saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.19k stars 5.48k forks source link

[BUG] Windows: ps.psaux requires a "ps" command to work #65252

Open dafyddj opened 1 year ago

dafyddj commented 1 year ago

Description The execution function ps.psaux requires the ps command to work which is non-standard on Windows

Setup

Standard Windows install using .exe installer

Steps to Reproduce the behavior

PS C:\Users\User> salt-call ps.psaux Python
Error running 'ps.psaux': Unable to run command 'ps aux'
with the context '{'cwd': 'C:\\Users\\User', 'shell': False,
'env': {'ALLUSERSPROFILE': 'C:\\ProgramData', 'APPDATA':
'C:\\Users\\User\\AppData\\Roaming', 'CommonProgramFiles':
'C:\\Program Files\\Common Files',
'CommonProgramFiles(Arm)': 'C:\\Program Files (Arm)\\Common
Files', 'CommonProgramFiles(x86)': 'C:\\Program Files
(x86)\\Common Files', 'CommonProgramW6432': 'C:\\Program
Files\\Common Files', 'COMPUTERNAME': 'WINDOWS-K3E3JQ8',
'ComSpec': 'C:\\Windows\\system32\\cmd.exe', 'DriverData':
'C:\\Windows\\System32\\Drivers\\DriverData', 'EFC_5008':
'0', 'FPS_BROWSER_APP_PROFILE_STRING': 'Internet Explorer',
'FPS_BROWSER_USER_PROFILE_STRING': 'Default', 'HOMEDRIVE':
'C:', 'HOMEPATH': '\\Users\\User', 'LOCALAPPDATA':
'C:\\Users\\User\\AppData\\Local', 'LOGONSERVER':
'\\\\WINDOWS-K3E3JQ8', 'NUMBER_OF_PROCESSORS': '2',
'OneDrive': 'C:\\Users\\User\\OneDrive', 'OS': 'Windows_NT',
'Path':
'C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program
Files\\Salt
Project\\Salt;C:\\Users\\User\\AppData\\Local\\Microsoft\\WindowsApps;',
'PATHEXT':
'.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL',
'PROCESSOR_ARCHITECTURE': 'AMD64', 'PROCESSOR_IDENTIFIER':
'ARMv8 (64-bit) Family 8 Model 0 Revision   0, QEMU',
'PROCESSOR_LEVEL': '0', 'PROCESSOR_REVISION': '0000',
'ProgramData': 'C:\\ProgramData', 'ProgramFiles':
'C:\\Program Files', 'ProgramFiles(Arm)': 'C:\\Program Files
(Arm)', 'ProgramFiles(x86)': 'C:\\Program Files (x86)',
'ProgramW6432': 'C:\\Program Files', 'PSModulePath':
'C:\\Users\\User\\Documents\\WindowsPowerShell\\Modules;C:\\Program
Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules',
'PUBLIC': 'C:\\Users\\Public', 'SESSIONNAME': 'Console',
'SystemDrive': 'C:', 'SystemRoot': 'C:\\Windows', 'TEMP':
'C:\\Users\\User\\AppData\\Local\\Temp', 'TMP':
'C:\\Users\\User\\AppData\\Local\\Temp', 'USERDOMAIN':
'WINDOWS-K3E3JQ8', 'USERDOMAIN_ROAMINGPROFILE':
'WINDOWS-K3E3JQ8', 'USERNAME': 'User', 'USERPROFILE':
'C:\\Users\\User', 'windir': 'C:\\Windows'}, 'stdin': None,
'stdout': -1, 'stderr': -2, 'with_communicate': True,
'timeout': None, 'bg': False}', reason: [WinError 2] The
system cannot find the file specified

Expected behavior

Either for the function to work as expected, or the documentation to make clear that it doesn't work on Windows.

Screenshots If applicable, add screenshots to help explain your problem.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) ```yaml Salt Version: Salt: 3006.3 Python Version: Python: 3.10.13 (heads/main:7ee24e6, Sep 6 2023, 02:19:49) [MSC v.1936 64 bit (AMD64)] Dependency Versions: cffi: 1.14.6 cherrypy: 18.6.1 dateutil: 2.8.1 docker-py: Not Installed gitdb: 4.0.7 gitpython: Not Installed Jinja2: 3.1.2 libgit2: Not Installed looseversion: 1.0.2 M2Crypto: Not Installed Mako: Not Installed msgpack: 1.0.2 msgpack-pure: Not Installed mysql-python: Not Installed packaging: 22.0 pycparser: 2.21 pycrypto: Not Installed pycryptodome: 3.10.1 pygit2: Not Installed python-gnupg: 0.4.8 PyYAML: 6.0.1 PyZMQ: 25.0.2 relenv: 0.13.10 smmap: 4.0.0 timelib: 0.2.4 Tornado: 4.5.3 ZMQ: 4.3.4 System Versions: dist: locale: cp1252 machine: AMD64 release: 10 system: Windows version: 10 10.0.22621 SP0 Multiprocessor Free ```

Additional context Add any other context about the problem here.

twangboy commented 1 year ago

We need to look at using psutil to emulate ps aux behavior so that it is platform agnostic. If that's not possible, then use the Get-Process commandlet in PowerShell