- 1 year ago
Puppet on WIndows: creating a resource only if a registry entry is (not) present
In Puppet, you can use the registry_value
and ensure_resource
functions to conditionally create a resource based on the presence or absence of a registry entry. Here's an example:
puppet$registry_entry = 'HKLM\Software\MyApp\MyEntry'
$resource_to_create = 'my_resource_to_create'
$entry_exists = registry_value($registry_entry)
if $entry_exists == undef {
notify { "Registry entry not found: ${registry_entry}": }
ensure_resource($resource_to_create)
} else {
notify { "Registry entry found: ${registry_entry}": }
}
In this example, the $registry_entry
variable stores the registry key and value you want to check. The $resource_to_create
variable holds the resource you want to create if the registry entry is not found.
The registry_value
function is used to check if the registry entry exists. If it returns undef
, indicating the entry is not found, a notification is displayed, and the ensure_resource
function is used to create the desired resource.
If the registry entry exists, a different notification is displayed indicating its presence.
Please note that you need to have the registry
module installed for this to work. You can install it using the following command:
shellpuppet module install puppetlabs-registry
Ensure you have the necessary permissions to read the registry and modify resources when running Puppet on Windows.