Akom's Tech Ruminations

Various tech outbursts - code and solutions to practical problems

Puppet: recursively delete a Windows Registry key

Posted by Admin • Wednesday, October 14. 2015 • Category: DevOps
Puppet forge has a registry provider that allows one to manage a key or value. What it cannot do is delete a whole tree starting at a particular key. So, hacks to the rescue:


  # deletes the whole tree if it exists
  define registry_wipe_tree($key = $title) {
    exec {"Purge registry $key":
      path => ['c:/windows/system32'],
      command => "reg DELETE \"${key}\" /f",
      onlyif => "reg QUERY \"${key}\"",
    }
  }
 


Now if you want to, say, disable Java auto-update:

registry_wipe_tree{'HKLM\SOFTWARE\JavaSoft\Java Update':}
registry_wipe_tree{'HKLM\SOFTWARE\Wow6432Node\JavaSoft\Java Update': }