I keep the Installation of the dbatools.io PowerShell module updated on my MSSQL Servers with a simple Ansible playbook which includes the following task:
#################### UPDATE DBATOOLS ####################
- name: uppdate dbatools
win_shell: |
if ([Net.ServicePointManager]::SecurityProtocol -match "Tls12") {
write-host "OK: tls 12 active"
}
else{
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
write-host "SET: tls 12 was activated"
}
if ((Get-PSRepository).name -notLike "PSGallery") {
write-host "SET: PSGallery registering"
Register-PSRepository -Default
}
else {
write-host "OK: PSGallery existing"
}
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
write-host "SET: updating dbatools"
Update-Dbatools -Cleanup -Confirm:$false
# Same as on install except for install command at the end
when: is_installed.stdout.find('true') != -1 ## used "find", because stdout contains /r/n as it is a list / find easier then cleaning var
This Task does work but it returns the following error, every time it has to cleanup an old version of dbatools:
fatal: [server.domain.local]: FAILED! => {"changed": false, "module_stderr": "#< CLIXML\r\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 4294967295}
I use ignore_errors: yes
on it so it won't spoil my results, but ultimately I'd like to solve this issue reliably.
If I execute this command directly via remote connection on any host, it works without errors.
When leaving the -Cleanup
option away it also works without errors but old versions of dbatools will not been deleted and it would add up over time.
Any ideas how this error can correctly be handled on Ansible?
Error Message with high verbosity:
redirecting (type: modules) ansible.builtin.win_shell to ansible.windows.win_shell
Using module file /runner/requirements_collections/ansible_collections/ansible/windows/plugins/modules/win_shell.ps1
Pipelining is enabled.
<SQL-Server-IP> ESTABLISH WINRM CONNECTION FOR USER: ansible-service-user on PORT 5986 TO SQL-Server-IP
EXEC (via pipeline wrapper)
fatal: [SQL-Server-FQDN]: FAILED! => {
"changed": false,
"module_stderr": "#< CLIXML\r\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 4294967295
}