Jira (BOLT-1474) Make facts and vars accessible from inside a Task

7 views
Skip to first unread message

Nick Maludy (JIRA)

unread,
Jul 16, 2019, 4:32:02 PM7/16/19
to puppe...@googlegroups.com
Nick Maludy created an issue
 
Puppet Task Runner / New Feature BOLT-1474
Make facts and vars accessible from inside a Task
Issue Type: New Feature New Feature
Assignee: Unassigned
Created: 2019/07/16 1:31 PM
Priority: Normal Normal
Reporter: Nick Maludy

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

  1. 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')

  1. 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)

  1. 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'))

 

 

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Yasmin Rajabi (JIRA)

unread,
Aug 19, 2019, 6:41:03 PM8/19/19
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages