I have a problem when trying to use powershell 7.x on a Windows host from Ansible. I can reproduce it at work (AAP 4.5.32) as well in my homelab (AWX 24.6.1)
In my lab I run Execution Environment quay.io / ansible / awx-ee:24.6.1, [latest] produces the same errors
pwsh 7.4 and 7.6 behave the same.
The error is “Failed to compile C# code:\r\nerror CS0041: Unexpected error writing debug information – ‘The version of Windows PDB writer is older than required: ‘diasymreader.dll’’”. Full log dumps below.
I searched the freshly new installed testmachines (Windows 2025) for diasymreader.dll and it’s only present in .\Microsoft.NET\Framework* folders for version 2.x and 4.x
The testmachines have only powershell 7 and vscode installed
I have this playbook:
---
- name: Test pwsh script execution
hosts: all
gather_facts: false
tasks:
- name: Run a Powershell script
ansible.windows.win_powershell:
script: |
Write-Output "This is a Powershell script running on the target host."
Write-Output "$($PSVersionTable.PSVersion.tostring())"
executable: pwsh.exe
...
Below output from running the playbook on two hosts connecting through WinRM with pwsh 7.4 and 7.6. Despite the error the script is executed. Running with a PSRP connection gives the same result
ansible-playbook [core 2.15.12]
config file = None
configured module search path = ['/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /runner/requirements_collections:/runner/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-playbook
python version = 3.9.19 (main, Jun 11 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3)] (/usr/bin/python3)
jinja version = 3.1.4
libyaml = True
No config file found; using defaults
SSH password:
setting up inventory plugins
Loading collection ansible.builtin from
host_list declined parsing /runner/inventory/hosts as it did not pass its verify_file() method
Parsed /runner/inventory/hosts inventory source with script plugin
Loading collection ansible.windows from /usr/share/ansible/collections/ansible_collections/ansible/windows
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.9/site-packages/ansible/plugins/callback/default.py
Loading callback plugin awx_display of type stdout, v2.0 from /usr/local/lib/python3.9/site-packages/ansible_runner/display_callback/callback/awx_display.py
Skipping callback 'awx_display', as we already have a stdout callback.
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: PwshTest.playbook.yml ************************************************
Positional arguments: playbooks/PwshTest.playbook.yml
verbosity: 4
remote_user: ansible@NUCLABS.NL
connection: smart
timeout: 10
ask_pass: True
become_method: sudo
tags: ('all',)
inventory: ('/runner/inventory/hosts',)
extra_vars: ('@/runner/env/extravars',)
forks: 5
1 plays in playbooks/PwshTest.playbook.yml
PLAY [Test pwsh script execution] **********************************************
TASK [Run a Powershell script] *************************************************
task path: /runner/project/playbooks/PwshTest.playbook.yml:8
Using module file /usr/share/ansible/collections/ansible_collections/ansible/windows/plugins/modules/win_powershell.ps1
Pipelining is enabled.
Using module file /usr/share/ansible/collections/ansible_collections/ansible/windows/plugins/modules/win_powershell.ps1
Pipelining is enabled.
<server1.nuclabs.nl> ESTABLISH WINRM CONNECTION FOR USER: ansible@NUCLABS.NL on PORT 5985 TO server1.nuclabs.nl
calling kinit with pexpect for principal ansible@NUCLABS.NL
<server2.nuclabs.nl> ESTABLISH WINRM CONNECTION FOR USER: ansible@NUCLABS.NL on PORT 5985 TO server2.nuclabs.nl
calling kinit with pexpect for principal ansible@NUCLABS.NL
EXEC (via pipeline wrapper)
EXEC (via pipeline wrapper)
changed: [server1.nuclabs.nl] => {
"changed": true,
"debug": [],
"error": [
{
"category_info": {
"activity": "",
"category": "OperationStopped",
"category_id": 14,
"reason": "InvalidOperationException",
"target_name": "",
"target_type": ""
},
"error_details": null,
"exception": {
"help_link": null,
"hresult": -2146233079,
"inner_exception": null,
"message": "Failed to compile C# code:\\r\\nerror CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: 'diasymreader.dll''",
"source": null,
"type": "System.InvalidOperationException"
},
"fully_qualified_error_id": "Failed to compile C# code:\\r\\nerror CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: 'diasymreader.dll''",
"output": "Failed to compile C# code:\\r\\nerror CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: \\r\\n'diasymreader.dll''\\r\\nAt line:259 char:17\\r\\n+ ... throw [InvalidOperationException]\\"Failed to compile C# co ...\\r\\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\r\\n + CategoryInfo : OperationStopped: (:) [], InvalidOperationException\\r\\n + FullyQualifiedErrorId : Failed to compile C# code:\\r\\nerror CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: \\r\\n'diasymreader.dll''\\r\\n \\r\\n",
"pipeline_iteration_info": [],
"script_stack_trace": "at <ScriptBlock>, <No file>: line 259\\r\\nat <ScriptBlock>, <No file>: line 30",
"target_object": null
}
],
"host_err": "",
"host_out": "",
"information": [],
"invocation": {
"module_args": {
"arguments": null,
"chdir": null,
"creates": null,
"depth": 2,
"error_action": "continue",
"executable": "pwsh.exe",
"parameters": null,
"removes": null,
"script": "Write-Output \\"This is a Powershell script running on the target host.\\"\\nWrite-Output \\"The survey message is: $env:target_environment\\"\\nWrite-Output \\"$($PSVersionTable.PSVersion.tostring())\\"\\n",
"sensitive_parameters": null
}
},
"output": [
"This is a Powershell script running on the target host.",
"The survey message is: ",
"7.4.7"
],
"result": {},
"verbose": [],
"warning": []
}
changed: [server2.nuclabs.nl] => {
"changed": true,
"debug": [],
"error": [
{
"category_info": {
"activity": "",
"category": "OperationStopped",
"category_id": 14,
"reason": "InvalidOperationException",
"target_name": "",
"target_type": ""
},
"error_details": null,
"exception": {
"help_link": null,
"hresult": -2146233079,
"inner_exception": null,
"message": "Failed to compile C# code:\\r\\nerror CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: 'diasymreader.dll''",
"source": null,
"type": "System.InvalidOperationException"
},
"fully_qualified_error_id": "Failed to compile C# code:\\r\\nerror CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: 'diasymreader.dll''",
"output": "Failed to compile C# code:\\r\\nerror CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: \\r\\n'diasymreader.dll''\\r\\nAt line:259 char:17\\r\\n+ ... throw [InvalidOperationException]\\"Failed to compile C# co ...\\r\\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\r\\n + CategoryInfo : OperationStopped: (:) [], InvalidOperationException\\r\\n + FullyQualifiedErrorId : Failed to compile C# code:\\r\\nerror CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: \\r\\n'diasymreader.dll''\\r\\n \\r\\n",
"pipeline_iteration_info": [],
"script_stack_trace": "at <ScriptBlock>, <No file>: line 259\\r\\nat <ScriptBlock>, <No file>: line 30",
"target_object": null
}
],
"host_err": "",
"host_out": "",
"information": [],
"invocation": {
"module_args": {
"arguments": null,
"chdir": null,
"creates": null,
"depth": 2,
"error_action": "continue",
"executable": "pwsh.exe",
"parameters": null,
"removes": null,
"script": "Write-Output \\"This is a Powershell script running on the target host.\\"\\nWrite-Output \\"The survey message is: $env:target_environment\\"\\nWrite-Output \\"$($PSVersionTable.PSVersion.tostring())\\"\\n",
"sensitive_parameters": null
}
},
"output": [
"This is a Powershell script running on the target host.",
"The survey message is: ",
"7.6.1"
],
"result": {},
"verbose": [],
"warning": []
}
PLAY RECAP *********************************************************************
server1.nuclabs.nl : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
server2.nuclabs.nl : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Below the output of the playbook running without the executable = pwsh.exe setting, but the extra_var ansible_psrp_configuration_name
The error is the same, but the script is not executed and the play is failed
{
"ansible_connection": "psrp",
"ansible_psrp_auth": "kerberos",
"ansible_psrp_protocol": "http",
"ansible_psrp_configuration_name": "powershell.7"
}
ansible-playbook [core 2.15.12]
config file = None
configured module search path = ['/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
ansible collection location = /runner/requirements_collections:/runner/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-playbook
python version = 3.9.19 (main, Jun 11 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3)] (/usr/bin/python3)
jinja version = 3.1.4
libyaml = True
No config file found; using defaults
SSH password:
setting up inventory plugins
Loading collection ansible.builtin from
host_list declined parsing /runner/inventory/hosts as it did not pass its verify_file() method
Parsed /runner/inventory/hosts inventory source with script plugin
Loading collection ansible.windows from /usr/share/ansible/collections/ansible_collections/ansible/windows
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python3.9/site-packages/ansible/plugins/callback/default.py
Loading callback plugin awx_display of type stdout, v2.0 from /usr/local/lib/python3.9/site-packages/ansible_runner/display_callback/callback/awx_display.py
Skipping callback 'awx_display', as we already have a stdout callback.
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: PwshTest.playbook.yml ************************************************
Positional arguments: playbooks/PwshTest.playbook.yml
verbosity: 4
remote_user: ansible@NUCLABS.NL
connection: smart
timeout: 10
ask_pass: True
become_method: sudo
tags: ('all',)
inventory: ('/runner/inventory/hosts',)
extra_vars: ('@/runner/env/extravars',)
forks: 5
1 plays in playbooks/PwshTest.playbook.yml
PLAY [Test pwsh script execution] **********************************************
TASK [Run a Powershell script] *************************************************
task path: /runner/project/playbooks/PwshTest.playbook.yml:8
Using module file /usr/share/ansible/collections/ansible_collections/ansible/windows/plugins/modules/win_powershell.ps1
Pipelining is enabled.
<server1.nuclabs.nl> ESTABLISH PSRP CONNECTION FOR USER: ansible@NUCLABS.NL ON PORT 5985 TO server1.nuclabs.nl
Using module file /usr/share/ansible/collections/ansible_collections/ansible/windows/plugins/modules/win_powershell.ps1
Pipelining is enabled.
<server2.nuclabs.nl> ESTABLISH PSRP CONNECTION FOR USER: ansible@NUCLABS.NL ON PORT 5985 TO server2.nuclabs.nl
PSRP: EXEC (via pipeline wrapper)
PSRP: EXEC (via pipeline wrapper)
The full traceback is:
Failed to compile C# code:\r
error CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: 'diasymreader.dll''
At line:262 char:17\r
+ … throw [InvalidOperationException]"Failed to compile C# co …\r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], InvalidOperationException
+ FullyQualifiedErrorId : Failed to compile C# code:\r
error CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: 'diasymreader.dll''\r
\r
ScriptStackTrace:\r
at Add-CSharpType, <No file>: line 262\r
at <ScriptBlock>, <No file>: line 19\r
at <ScriptBlock><End>, <No file>: line 143\r
at <ScriptBlock>, <No file>: line 11\r
fatal: [server2.nuclabs.nl]: FAILED! => {
"changed": false,
"msg": "internal error: failed to run exec_wrapper action module_powershell_wrapper: Failed to compile C# code:\\r\\nerror CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: 'diasymreader.dll''"
}
The full traceback is:
Failed to compile C# code:\r
error CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: 'diasymreader.dll''
At line:262 char:17\r
+ … throw [InvalidOperationException]"Failed to compile C# co …\r
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], InvalidOperationException
+ FullyQualifiedErrorId : Failed to compile C# code:\r
error CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: 'diasymreader.dll''\r
\r
ScriptStackTrace:\r
at Add-CSharpType, <No file>: line 262\r
at <ScriptBlock>, <No file>: line 19\r
at <ScriptBlock><End>, <No file>: line 143\r
at <ScriptBlock>, <No file>: line 11\r
fatal: [server1.nuclabs.nl]: FAILED! => {
"changed": false,
"msg": "internal error: failed to run exec_wrapper action module_powershell_wrapper: Failed to compile C# code:\\r\\nerror CS0041: Unexpected error writing debug information -- 'The version of Windows PDB writer is older than required: 'diasymreader.dll''"
}
PLAY RECAP *********************************************************************
server1.nuclabs.nl : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
server2.nuclabs.nl : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0