Instead of using Puppet exported resources Show archive.org snapshot you can use the puppetdb_query Show archive.org snapshot feature.
This can result in more complex code but has several benefits:
puppetdb queries
to get the resources you want than with the limited filtering options of exported resourcesdefined types
defined types
duplicate declaration
issue. Usually you will create a wrapper defined type which contains for example the node name in the title. The wrapper resource contains an ensure_resource
with the resource you really want to manageOne example is used by us in environments::railscomplete::dbcollector
:
$vhost_types = ['\'Environments::Elixir::Vhost\'',
'\'Environments::Rails::Vhost\'',
'\'Environments::Php::Vhost\'',
'\'Environments::Python::Vhost\'',
]
$vhosts = puppetdb_query("resources {type in ${vhost_types} and parameters.dbbackend = '${dbbackend}'}")
$vhosts.each |$vhost| {
ensure_resource('environments::railscomplete::db', $vhost['parameters']['dbuser'], {
'password' => $vhost['parameters']['dbpassword'],
'type' => $type,
'extensions' => $vhost['parameters']['dbextensions'],
'schemas' => $vhost['parameters']['dbschemas'],
'charset' => $vhost['parameters']['dbencoding'],
'collate' => $vhost['parameters']['dbcollate'],
'host' => $host,
})
}
Instead of exporting a environments::railscomplete::db
resource on the application servers we just collectd all the vhosts
with a specific dbbackend
. A vhost
can be configured on multiple servers. If we've used exported resources the environments::railscomplete::db
resource type would not contain the resources it contains now but would be a wrapper using an additional resource type utilizing ensure_resources
. This is more complex than just fetching the information straight out of the PuppetDB and applying it with .each
.
This highly depends on the scenario. Usually you should use exported resources because it's the more simple solution. But building wrapper resources and understanding them can be more complex than just using a puppetdb_query
.