puppetlabs / bolt

Bolt is an open source orchestration tool that automates the manual work it takes to maintain your infrastructure on an as-needed basis or as part of a greater orchestration workflow. It can be installed on your local workstation and connects directly to remote nodes with SSH or WinRM, so you are not required to install any agent software.
https://puppet.com/docs/bolt/latest/bolt.html
Apache License 2.0
497 stars 225 forks source link

Make `bolt plan new` help users write `run_*` plans #2674

Closed op-ct closed 2 years ago

op-ct commented 3 years ago

Use Case

I've been thinking more about the bolt plan new --script <script_name> code generation @adreyer proposed in #2654.

It might be handy to give bolt plan new options that wrap existing tasks and plans in run_*() functions and scaffold their parameters (since Bolt already knows them).

Describe the Solution You Would Like

A clear and concise description of what you want to happen.

bolt plan new --pp \
  --task my_project::task_a \
  --task-with my_project::task_b \
  --command 'date utc' \
  --plan my_project::plan_c \
    my_project::new_plan

With a result like:

# This is the structure of a simple plan. To learn more about writing
# Puppet plans, see the documentation: http://pup.pt/bolt-puppet-plans

# The summary sets the description of the plan that will appear
# in 'bolt plan show' output. Bolt uses puppet-strings to parse the
# summary and parameters from the plan.
# @summary A plan created with bolt plan new.
# @param targets The targets to run on.
plan my_project::new_plan (
  TargetSpec $targets = "localhost"
) {

  # Parameters scaffolded based on task's .json:
  $task1_result = run_task( 'my_project::task_a', $targets, {
      'param_a' => 'CHANGEME', # required String
      # 'param_b' => [],       # optional Array
   })

  $task2_result = run_task_with( 
    'my_project::task_b,
    $targets,
  ) |$t| {{
    'param_c' => Sensitive.new('CHANGEME'),  # Required sensitive String
    'param_d' => undef,   # alternate scaffolding for an optional parameter
  }}

  $command1_result = run_command('date --utc', $targets)

  $plan1_result = run_plan( 
    'my_project::plan_c',
    {
      'targets' => $targets,
      'param_e' => {}, # required Hash
    }
  )
  return $plan1_result  # the last scaffolded result?
}

Additional Context

This is not carefully thought out at all—I just want to propose it somewhere for comment, and it's a pretty big chunk of code to throw in the Slack.

lucywyman commented 3 years ago

I think the solution for this is something along the lines of having "plan templates" that users can create and then make new plans from. Ideally templates would be available in modules, would be in a well-known or common language. We could start by shipping our own Bolt templates, and as an improvement let users write + ship their own templates.

github-actions[bot] commented 2 years ago

This issue has not had activity for 60 days and will be marked as stale. If this issue continues to have no activity for 7 days, it will be closed.

github-actions[bot] commented 2 years ago

This issue is stale and has been closed. If you believe this is in error, or would like the Bolt team to reconsider it, please reopen the issue.