[英]Use Regex in registry_data_exists Resource in Chef Recipe
我正在创建厨师食谱,并尝试使用registry_key资源创建/更新注册表项。 我如何使用正则表达式来验证注册表项的存在,并且仅在必要时进行更新
registry_key'HKLM\\\\Software\\\\Microsoft\\\\WindowsNT\\\\CurrentVersion\\\\Winlogon' do values [{ name: 'SCRemoveOption', type: :string, data: '1', }] # recursive true action :create not_if { registry_data_exists?('HKLM\\\\Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Winlogon',{ name: 'SCRemoveOption', type: :string, data: '1' } ,:x86_64) } end
如果注册表项与数据1或2或3一起存在,则无需进行udpate,否则Registry_key-data应更新为1。
not_if { registry_data_exists?('HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon',{ name: 'SCRemoveOption', type: :string, data: '([1-3])'} ,:x86_64) }
(对以前的努力表示歉意)
我更喜欢使用powershell_script资源,因为我知道PS语法比ruby / Chef好。 我曾经检查安全策略是否已启用/禁用,如下所示:
powershell_script 'my_script' do
guard_interpreter :powershell_script
cwd 'C:\Temp'
code <<-EOH
<...set the registry key(s)...>
EOH
not_if '(get-itemproperty HKLM:\\System\\CurrentControlSet\\Control\\Lsa).DisableDomainCreds -eq "1"'
end
也许您可以适应使其与数组或值一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.