Description
Summary
With OpenSSH and WinRM enabled on Windows Server 2025 build 26100 I have hundreds of tasks that work all ok using both ssh and winrm. Ansible version in use is 2.17.4, authentication, shell type, etc have all been set and almost everything seems to work perfectly.
There is, however, one single command that for some reason works only with winrm but gets stuck with ssh unless redirecting stderr. The hang could be also reproduced on PowerShell command line so the root cause could be a PowerShell/Windows issue but I'm filing this issue to at least raise awareness even if fixing it would be out of scope for the Ansible project.
Issue Type
Bug Report
Component Name
windows
Ansible Version
$ ansible --version
ansible [core 2.17.4]
config file = None
configured module search path = ['/home/testuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/testuser/ansible/ansible-2.17/lib64/python3.11/site-packages/ansible
ansible collection location = /home/testuser/.ansible/collections:/usr/share/ansible/collections
executable location = /home/testuser/ansible/ansible-2.17/bin/ansible
python version = 3.11.7 (main, Aug 23 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3)] (/home/testuser/ansible/ansible-2.17/bin/python3.11)
jinja version = 3.1.4
libyaml = True
$ ansible-galaxy collection list | grep windows
ansible.windows 2.5.0
community.windows 2.3.0
Configuration
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = None
EDITOR(env: EDITOR) = vi
PAGER(env: PAGER) = less
OS / Environment
RHEL 9
Steps to Reproduce
To reproduce, first initialize the test file on the target with:
echo test | Set-Content C:\ProgramData\ssh\sshd_config.test
Then, this works with winrm but fails with ssh, same thing if using the win_shell module instead:
- name: Validate sshd configuration file
ansible.windows.win_command: >
C:\Windows\System32\OpenSSH\sshd.exe -tf C:\ProgramData\ssh\sshd_config.test
changed_when: false
So far the only way I have gotten it to work is like this:
- name: Validate sshd configuration file
ansible.windows.win_powershell:
error_action: stop
script: |
$p = Start-Process `
-FilePath C:\Windows\System32\OpenSSH\sshd.exe `
-ArgumentList "-tf C:\ProgramData\ssh\sshd_config.test" `
-WorkingDirectory C:\ProgramData\ssh `
-RedirectStandardError .\.tmp `
-NoNewWindow `
-PassThru `
-Wait
if ($p.ExitCode) {
$Ansible.Failed = $true
$Ansible.Result = Get-Content -Raw .\.tmp
del .\.tmp
}
changed_when: false
Removing the RedirectStandardError option would cause this to fail as well.
Note that if logging in to the same Windows host over SSH then the same Start-Process command would similarly complete or not depending on the RedirectStandardError option. If omitting the option one could however press enter and get back to the command prompt.
Expected Results
The task completes normally using SSH.
Actual Results
The task gets stuck using SSH.
Code of Conduct
- I agree to follow the Ansible Code of Conduct