puppetlabs / puppetlabs/bolt

Add a way to selectively disable `run_command` & co output to `stdout` on `bolt plan`

Open
#3,301 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature
Dominant language
Ruby
Stars
558
Forks
224
Avg merge
1h 4m
Merged PRs (30d)
1

Description

Use Case

I followed the breadcrumbs and ended up looking at #2653 .

I have the following block of code as part of a plan to do some testing:

    $pr = run_command(
        "/opt/puppetlabs/bin/puppet agent -t --noop --color=true --detailed-exitcodes --environment ${branch}",
        $targets, '_run_as' => 'root')

    $pr.to_data.each |$result| {
        # Detailed exit codes: https://www.puppet.com/docs/puppet/8/man/agent#usage-notes
         if $result['exit_code'] == 0 {
            out::message("${result['target']}: No change")
        } elsif $result['exit_code'] == 2 {
            out::message("${result['target']}: Succeeded with changes")
            out::message($result['value']['stdout'])
        } else {
            out::message("${result['target']}: Fail or didn't run")
            out::message($result['value']['stdout'])
        }
    }

Problem is, I get all the output from puppet on stdout even though 95% of hosts should be "No change". This is very verbose and I'd like to be able to summarize the command. So capturing the output is good, displaying it by default is good, but having a way to not do it on a run_command basis would be great.

Describe the Solution You Would Like

A _print option on run_command & related, set to true by default. If set to false, does not print to the CLI.

Describe Alternatives You've Considered

Since we run puppet in test mode to get a clear output, we could do one run without test mode, one run in term mode for those who fail, but that seems overkill. Another option would be to disable showing the output by default, but in the grander picture, it doesn't seem like the best approach.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the run_command entry point and the related command functions used by bolt plan, then follow where their captured output is sent to the CLI. Check how plan options are parsed and documented. Done means a per-command _print option can suppress CLI output while preserving captured results, with the default behavior unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
cli, devops
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.