【问题标题】:Use Regex in registry_data_exists Resource in Chef Recipe在 Chef Recipe 的 registry_data_exists 资源中使用 Regex
【发布时间】:2017-12-07 09:04:31
【问题描述】:

我正在创建厨师食谱并尝试使用 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,则无需更新,否则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) }

【问题讨论】:

    标签: windows chef-infra registrykey


    【解决方案1】:

    (为之前的努力道歉)

    我更喜欢使用 powershell_script 资源,因为我比 ruby​​/Chef 更了解 PS 语法。我曾经检查安全策略是否启用/禁用如下:-

      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
    

    也许您可以调整以使其与数组或值一起使用。

    【讨论】:

    • 克雷格,谢谢你的建议,我需要验证数据而不是密钥是否存在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 2015-09-25
    相关资源
    最近更新 更多