我在MSSQL服务器上更新了dbatools.io PowerShell模块的安装,使用了一个简单的Ansible剧本,其中包括以下任务:
#################### 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此任务确实工作,但它返回以下错误,每次必须清除旧版本的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}我在上面使用ignore_errors: yes,这样它不会破坏我的结果,但最终我想要可靠地解决这个问题。
如果我直接通过远程连接在任何主机上执行这个命令,它就可以正常工作。当不使用-Cleanup选项时,它也能正常工作,但是旧版本的dbatools不会被删除,并且会随着时间的推移而增加。
有什么想法可以正确处理这个错误在Ansible上吗?
高度详细的错误消息:
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
}发布于 2022-06-01 08:42:44
现在,我已经将任务从win_shell更改为ansible.windows.win_powershell。该模块能够处理由清理过程生成的警告:
"warning": [
"The version '1.1.97' of module 'dbatools' is currently in use. Retry the operation after closing the applications.",
"Unable to remove dbatools version [1.1.97] due to: \n\tSystem.Exception: Module 'dbatools' is in currently in use or you don't have the required permissions."基于此,我将在不使用Update-Dbatools选项的情况下执行-cleanup命令。之后,我将添加第二个任务来清理旧的dbatools版本。
为什么在手动执行更新/清理时不会出现这种情况,这对我来说是个谜。
https://serverfault.com/questions/1101123
复制相似问题