Plan not running in order
Describe the Bug
When I run the plan shown below, the second target shows the prompt prior to the two out messages that are in the code before it.
Expected Behavior
I expect plans to run, and display output, in the same order as they are coded.
Steps to Reproduce
Using this plan:
get_targets($targets).each |$target| {
out::message('')
$_agent_certname = run_command('puppet config print certname', $target, 'Getting agent certname').first['stdout'].rstrip()
if $target.name != $_agent_certname {
out::message("${target.name} has a certname of ${_agent_certname}")
}
run_command("ls -l ${_ca_ssl_dir}/ca/signed/${_agent_certname}.pem", $ca_server, 'Verify certificate exists')
$_expiration_check_description = 'Getting the expiration date of the agent certificate'
$_exiration_check_command = "cat ${_ca_ssl_dir}/ca/signed/${_agent_certname}.pem | openssl x509 -noout -enddate |cut -d '=' -f2"
$_expiration_date = run_command($_exiration_check_command, $ca_server, $_expiration_check_description).first['stdout'].rstrip()
out::message("${target.name}'s cert expriation: ${_expiration_date}")
# Confirm we are good to keep going
out::message('Shall we continue? Valid choices are:')
$menu = { 'y' => 'yes', 'n' => 'no' }
$selection = prompt::menu('Keep going?', $menu)
if $selection == 'no' {
out::message("Skipping remaining steps for ${target.name}")
} else {
# do other stuff
}
}
I get this:
$ bolt plan run ltn_sre_utils::servers::update_agent_cert --run-as root --sudo-password $boltpw --targets was-portal-web-qa-1.example.net,was-portal-web-qa-2.example.net
Starting: plan ltn_sre_utils::servers::update_agent_cert
Starting: Get ssldir path on col-ca.int.example.com
Finished: Get ssldir path with 0 failures in 1.69 sec
Starting: Getting agent certname on was-portal-web-qa-1.example.net
Finished: Getting agent certname with 0 failures in 1.05 sec
Starting: Verify certificate exists on col-ca.int.example.com
Finished: Verify certificate exists with 0 failures in 1.2 sec
Starting: Getting the expiration date of the agent certificate on col-ca.int.example.com
Finished: Getting the expiration date of the agent certificate with 0 failures in 1.22 sec
was-portal-web-qa-1.example.net's cert expriation: Oct 10 20:20:27 2028 GMT
Shall we continue? Valid choices are:
(y) yes
(n) no
Keep going?: n
Skipping remaining steps for was-portal-web-qa-1.example.net
Starting: Getting agent certname on was-portal-web-qa-2.example.net
Finished: Getting agent certname with 0 failures in 0.97 sec
Starting: Verify certificate exists on col-ca.int.example.com
Finished: Verify certificate exists with 0 failures in 1.17 sec
Starting: Getting the expiration date of the agent certificate on col-ca.int.example.com
(y) yes
(n) no
Keep going?: n
Finished: Getting the expiration date of the agent certificate with 0 failures in 1.23 sec
was-portal-web-qa-2.example.net's cert expriation: Oct 2 16:12:05 2023 GMT
Shall we continue? Valid choices are:
Skipping remaining steps for was-portal-web-qa-2.example.net
Finished: plan ltn_sre_utils::servers::update_agent_cert in 11.99 sec
Plan completed successfully with no result
Note that on the second target that the out::message()'s are showing up after the yes/no prompt.
Environment
- Version 3.27.4
- Platform macOS 13.5.2
Additional Context
I chatted about this in the community Slack and Nick Burgan posited this idea:
I’m guessing it has to do with the fact that the starting/finished messages are going through Bolt::Logger and prompt is writing directly to stderr
I'm also experiencing this issue with some of my plans
Thanks for the report. Will try to take a look soon.