Puppet Plan: choria::tasks::run

Defined in:
plans/tasks/run.pp

Overview

Runs a specific Puppet Task

When running in the background and in batches this does not imply that the task is completed between batches it means the task will be requested in these batches regardless of the state of the other nodes

When run in the foregroun it will wait up to 60 seconds for nodes to complete a task, if by then they did not complete the task it will move onto the next batch

Parameters:

  • nodes (Choria::Nodes)

    The nodes to run the task on

  • task (String)

    The name of the task to run

  • inputs (Hash)

    The inputs to pass to the task

  • background (Boolean) (defaults to: false)

    When true does not wait for the task to complete

  • silent (Boolean) (defaults to: false)

    Surpress logging of individual node results

  • batch_size (Integer) (defaults to: 0)

    When not 0, run the task on nodes in batches

  • tasks_environment (String[1]) (defaults to: "production")

    The environment to find tasks

  • catch_errors (Optional[Boolean]) (defaults to: undef)

    Whether to catch errors

  • batch_sleep_time (Integer) (defaults to: 2)
  • run_as (Optional[String[1]]) (defaults to: undef)


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
# File 'plans/tasks/run.pp', line 20

plan choria::tasks::run(
  Choria::Nodes $nodes,
  String $task,
  Hash $inputs,
  Boolean $background = false,
  Boolean $silent = false,
  Integer $batch_size = 0,
  Integer $batch_sleep_time = 2,
  Optional[String[1]] $run_as = undef,
  String[1] $tasks_environment = "production",
  Optional[Boolean] $catch_errors = undef,
) {
  $metadata = choria::tasks::metadata($task, $tasks_environment)

  choria::tasks::validate_input($inputs, $metadata)

  choria::run_playbook("choria::tasks::download_files",
    "nodes"             => $nodes,
    "task"              => $task,
    "files"             => $metadata["files"],
    "tasks_environment" => $tasks_environment,
    "catch_errors"      => $catch_errors,
  )

  if $background {
    $action = "bolt_tasks.run_no_wait"
  } else {
    $action = "bolt_tasks.run_and_wait"
  }

  info("Running task '${task}' on ${nodes.size} nodes")

  if $run_as {
    $run_as_property = { "run_as" => $run_as }
  } else {
    $run_as_property = {}
  }

  choria::task(
    "nodes"            => $nodes,
    "action"           => $action,
    "batch_size"       => $batch_size,
    "batch_sleep_time" => $batch_sleep_time,
    "silent"           => $silent,
    "_catch_errors"    => $catch_errors,
    "properties"       => {
      "task"           => $task,
      "files"          => $metadata["files"].stdlib::to_json,
      "input"          => $inputs.stdlib::to_json
    } + $run_as_property
  )
}