尝试使用以下代码在windows服务器上安装dotnet4.8:没有任何语法错误,问题是安装了dotnet代码,尝试了这么多可能性,但防护not_if似乎不起作用。我在stacktrace和copy pasted上看了很多例子,以确保没有遗漏一些东西。但到目前为止,没有任何帮助。
powershell_script 'install_dotnet48' do
guard_interpreter :powershell_script
not_if "Get-ChildItem 'HKLM:\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP' -Recurse | Get-ItemProperty -name version -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select Version | Where {$_.Version -match '4.8.0.3761'}"
code "#{cache_path}\\#{node['dotnet48']['version']}\\Setup.exe"
notifies :reboot_now, 'reboot[restart_server]', :immediately
end发布于 2020-08-18 20:00:23
当表达式返回true时,将激活powershell_script资源中的not_if防护。
not_if
防止在条件返回true时执行资源。
由于Version字符串没有匹配项,您尝试的命令可能未返回true。
也许你应该试试:
Where {$_.Version -match '4.8.03761'}防止安装.NET的更好方法可能是使用creates属性,并将其指向将在安装.NET时创建的文件/路径。例如:C:\windows\Microsoft.NET
powershell_script 'install_dotnet48' do
code "#{cache_path}\\#{node['dotnet48']['version']}\\Setup.exe"
creates 'C:/windows/Microsoft.NET'
notifies :reboot_now, 'reboot[restart_server]', :immediately
end这样,安装将是幂等的,并且报告为(up to date)而不是(skipped due to not_if)。
https://stackoverflow.com/questions/63446798
复制相似问题