| As an engineer trying to support multiple operating systems versions along with custom configurations i'm in need of an ability to access customizations at a node level from within a Task's execution (shell, python, ruby, powershell). Use Case #1
- I may need to execute a specific script on most nodes, except for a small handful of nodes where i need to execute a script but at a different path
- I may need to install some OS-level packages and on RHEL these packages are named X, on Debian these packages are named Y and on Windows with chocolatey they are named Z
Workarounds
- Call `run_task()` multiple times, one for each parameter/customization you want to pass in:
$linux_targets = $targets.filter |$t| { facts($t)['os']['family'] != 'windows'} |
$windows_targets = $targets.filter |$t| { facts($t)['os']['family'] == 'windows'} |
run_task('package', $linux_targets, action => 'install', name => 'openssh') |
run_task('package', $windows_targets, action => 'install', name => 'Win.OpenSSH32')
|
- Handle the customization inside the task script code itself
Ideas/thoughts
- Allow these customizations to be set at a node/group level using facts/vars. Then, inside my Task for running a script i can lookup the var's value and make a decision based on that within the task code.
$linux_targets = $targets.filter |$t| { facts($t)['os']['family'] != 'windows'} |
$windows_targets = $targets.filter |$t| { facts($t)['os']['family'] == 'windows'} |
|
$linux_targets.each |$t| { add_facts($t, package_name => 'openssh' } |
$windows_targets.each |$t| { add_facts($t, package_name => 'Win.OpenSSH32' } |
|
run_task('my_custom_package_task', $targets, action => 'install')
|
- Allow `run_task()` to be called with a different set of arguments for each target
$targets_args = $targets.reduce({}) |$memo, $t| { |
if facts($t)['os']['family'] == 'windows' { |
$package_name = 'Win.OpenSSH32' |
} |
else { |
$package_name = 'openssh' |
} |
$memo + { |
$t => |
{ |
'action' => 'install', |
'name' => $package_name, |
} |
} |
} |
|
run_task('my_custom_package_task', $targets_args)
|
- Allow `run_task()` argument list to reference a var/fact on a target
$target_args = $targets.each() |$memo, $t| { |
if facts($t)['os']['family'] == 'windows' { |
$package_name = 'Win.OpenSSH32' |
} |
else { |
$package_name = 'openssh' |
} |
set_var($t, {'package_name' => $package_name}) |
} |
|
run_task('package', $targets, |
action => 'install', |
name => var_reference('package_name'))
|
|