[英]Use Regex in registry_data_exists Resource in Chef Recipe
I am creating a chef recipe and trying to create/update Registry key using registry_key resource. 我正在创建厨师食谱,并尝试使用registry_key资源创建/更新注册表项。 How I can use regex to validate the presence of the registry key and only update if it is necessary 我如何使用正则表达式来验证注册表项的存在,并且仅在必要时进行更新
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
If the registry key exists with data 1 or 2 or 3, There is no need to udpate or else the registry_key-data should be updated to 1. 如果注册表项与数据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) }
(Apologies for previous effort) (对以前的努力表示歉意)
I have preferred using a powershell_script resource as I know PS syntax better than ruby/Chef. 我更喜欢使用powershell_script资源,因为我知道PS语法比ruby / Chef好。 I used to check with Security Policy was enabled/disabled as follows:- 我曾经检查安全策略是否已启用/禁用,如下所示:
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
Perhaps you can adapt to make it work with an array or values. 也许您可以适应使其与数组或值一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.