Puppet Plan: cd4peadm::support_bundle::collect_target_info
- Defined in:
- plans/support_bundle/collect_target_info.pp
Summary
Collects info from all CD4PE targetsOverview
This plan gathers data from all CD4PE targets so it can be included in the support bundle. A large portion of the data is collected by the ‘collect_target_info’ task which is done to optimize the number of SSH sessions we use as a consequence of data collection. It allows us to have one task collect most of the target specific data. The plan also collects facter data from each target. Log volumes for each container service are downloaded as well.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'plans/support_bundle/collect_target_info.pp', line 13
plan cd4peadm::support_bundle::collect_target_info(
Cd4peadm::Config $config,
String[1] $root_dir,
) {
$roles_for_targets = $config['all_targets'].reduce({}) |$memo, $target| {
$matching_roles = $config['roles'].filter |$role_name, $role_value| {
$role_value['targets'].any |$found_target| { $target == $found_target }
}
$memo + { $target => $matching_roles }
}
$target_data_dest = file::join($root_dir, 'targets')
without_default_logging() || {
run_command("mkdir ${target_data_dest}", 'localhost')
$config['all_targets'].each |$target| {
run_command("mkdir ${file::join($target_data_dest, $target.name)}", 'localhost')
}
}
$collect_info_results = run_task_with(
'cd4peadm::collect_target_info',
$config['all_targets'],
'_run_as' => 'root',
'_catch_errors' => true,
) |$target| {
$roles = $roles_for_targets[$target]
# Calculate what Journald logs should be collected
$journald_services = $roles.map |$role_name, $role_value| {
Cd4peadm::Support_bundle::Journald_services.new({
'role_name' => $role_name,
'services' => $role_value['services'].keys
})
}
# If applicable, provides the info needed by the task to connect to the database in order to run diagnostic queries.
# This works for AIO, but when we have multiple targets that can have the DB role, we'll just want the task to run on the main DB
# target.
if $roles['database'] != undef {
$database_info = Cd4peadm::Support_bundle::Database_info.new({
'container_name' => $roles['database']['services']['postgres']['container']['name'],
'database_user' => $roles['database']['services']['postgres']['admin_db_username'],
})
}
$target_params = {
'runtime' => $config['runtime'],
'journald_services' => $journald_services,
'database_info' => $database_info,
}
$target_params
}
without_default_logging() || {
# Download the tmp dir from the target
$collect_info_results.each |$result| {
$src_tmpdir = $result.value['tmpdir']
cd4peadm::download_file(
$src_tmpdir,
file::join($target_data_dest, $result.target.name),
$result.target,
{ '_run_as' => 'root' },
true
)
run_command("rm -r ${result.value['tmpdir']}", $result.target, '_run_as' => 'root', '_catch_errors' => true)
}
# Download log volumes for each target
$roles_for_targets.each |$target, $roles| {
$roles.each |$role_name, $role_value| {
$role_value['services'].each |$service_name, $service_value| {
$volume_src = file::join(cd4peadm::runtime::volume_dir(), $service_value['container']['log_volume_name'], '_data')
$service_dest = file::join($target_data_dest, $target.name, 'logs', $role_name, $service_name)
cd4peadm::download_file($volume_src, $service_dest, $target, { '_run_as' => 'root', '_catch_errors' => true }, true)
}
}
}
# Collect facts
$facter_keys = [
'load_averages',
'memory',
'disks',
'mountpoints',
'os',
'partitions',
'processors',
]
out::message('Gathering facts from targets...')
# Needed so facts are pulled from the target
apply_prep($config['all_targets'], { '_run_as' => 'root' })
$config['all_targets'].each |$target| {
$facts_hash = $target.facts
$facter_result = $facter_keys.reduce({}) |$fact_memo, $key| {
if($key in $facts_hash) {
$fact_memo + { $key => $facts_hash[$key] }
} else {
$fact_memo
}
}
$facts_dest_path = file::join($target_data_dest, $target.name, 'system')
file::write(file::join($facts_dest_path, 'facter.json'), to_json_pretty($facter_result))
}
}
}
|