Puppet Exported Resources
PUPPET being one of the configuration management tools provides a way where one can export resources such as files, ssh keys etc.. of a node to Puppet DB and then realize or collect it on other nodes.This allows to share the activities on one node to other nodes in the system, thereby helping to resolve dependencies among the components in the system.

If we used Puppet to deploy and manage a software solution and the solution had several components out of which one of them was a database component and other components accessed the database when their respective services were bought up, then in order to resolve the dependency between the database and other components, the database had to be populated with the initial data before bringing up any process successfully in the system. And to resolve this in Puppet, we can use exporting and collection of resources feature of Puppet as stated below.
- Assuming update of database with data is by running some existing SQL scripts.
<resource-type> { ‘SQL Update’: …… }
- Store the result of execution of SQL scripts in a file named “.db_status”. If SQL scripts ran successfully without any errors, then file “.db_status” was exported with text “Success” else if SQL scripts failed, then the file “.db_status” was not exported at all.
@@file { “${home_dir}/.db_status”:
content => “Success”
tag => “${::customer}_${::environment}_DB”,
require => <resource-type>[‘SQL Update’],
}
- Collect the above exported file “.db_status” on other system components. Here tagging ‘.db_status’ file using custom facts based on customer environment is helpful in uniquely identifying database belonging to a setup.
File <<| tag == “${::customer}_${::environment}_DB” |>>
- Next, check if the collected “.db_status” file on other system components had text “Success” , if so start the remaining services of the system else do not start the services at all assuming database is not updated.
exec { ‘Test DB Initialization’:
command => “cat ${home_dir}/.db_status | grep Success”,
path => “/usr/bin:/bin”,
}
service { ‘<service_name>’:
ensure => ‘running’,
require => Exec[‘Test DB Initialization’],
}
Notes:
- One should enable storeconfig in puppet master (puppet.conf), to use exporting and collection of resources. (set storeconfigs=True and storeconfigs_backend=puppetdb in puppet.conf)
- Realization of collected resources may not happen instantly , usually it takes two puppet runs on the servers where resources are collected.
- Same node can export and collect a resource.
