Whereas a class lets you group together related resources, a defined resource type lets you create new kinds of resources, and declare as many instances of them as you like. A defined resource type definition looks a lot like a class (defined_resource_type.pp
):
# Manage user and SSH key together define user_with_key( String $key_type, String $key, ) { user { $title: ensure => present, managehome => true, } file { "/home/${title}/.ssh": ensure => directory, owner => $title, group => $title, mode => '0700', } ssh_authorized_key { $title: user => $title, type => $key_type, key => $key, } }
You can see that instead of the class
keyword, we use the define
keyword. This tells Puppet that we are creating a defined resource type instead of a class. The type is called user_with_key
, and once it's defined, we can declare as many instances of it as we want, just like any other Puppet resource...