Bolt command run --env-var changes invoked shell
Describe the Bug
When performing 'bolt command run' the command is run using the default shell for the user specified in the targets. For example,
bolt command run 'nonsense' --targets [email protected] run the command nonsense in bash on 172.16.4.40 as user eng. If I add
a --env-var argument, the command no longer runs in the users default shell. It runs in /bin/sh.
Expected Behavior
bolt command run 'nonsense' --targets [email protected] --env-var ANY=thing should produce the same behavior as bolt command run 'nonsense' --targets [email protected]
Steps to Reproduce
bolt command run 'nonsense' --targets [email protected]
Started on [email protected]...
Failed on [email protected]:
The command failed with exit code 127
bash: line 1: nonsense: command not found
Failed on 1 target: [email protected]
Notice error at line 1 is reported by bash
bolt command run 'nonsense' --targets [email protected] --env-var ANY=thing
Started on [email protected]...
Failed on [email protected]:
The command failed with exit code 127
sh: 1: nonsense: not found
Failed on 1 target: [email protected]
Ran on 1 target in 0.34 sec
Notice error is reported by sh
Environment
Bolt version: 3.26.2 Server OS: Centos 7 Target OS: Linux Raspberry Pi September 22nd 2022 Kernel 5.15
Interesting. It looks like the Bolt::Shell::Bash#execute method is generalized to handle multiple commands (stitching them together with sh -c) , in the case of run_command (not considering run-as) we would know there is only one. Maybe we can look in to special casing that https://github.com/puppetlabs/bolt/blob/88d8c31428c61c3a35179ad69a2b2fbfebc7d3f5/lib/bolt/shell/bash.rb#L377-L381
I think @nicklewis implemented that feature originally, maybe he has an idea for this.
I should add, my real application uses 'bolt command run @' to run a full script of commands. I use the '--env-var' to parameterize the script to deliver several different results. I used the simple case of a single command to illustrate the bug.