Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssh_shell is being ignored inside playbook #212

Closed
fidojones opened this issue Jun 5, 2024 · 1 comment · Fixed by #213
Closed

ssh_shell is being ignored inside playbook #212

fidojones opened this issue Jun 5, 2024 · 1 comment · Fixed by #213

Comments

@fidojones
Copy link

fidojones commented Jun 5, 2024

I have defined ssh_shell: /bin/bash inside playbook, but in verbose mode it show that us /bin/sh to launch:

Test in version: v1.16.0

user: root
ssh_shell: /bin/bash

targets:
  prod:
    hosts: # list of hosts, user, name and port optional. 
      - {host: "192.168.1.42", user: "root", name: "h1"}

tasks:
  - name: Some tests
    targets: ["prod"]
    commands:
      - name: Testing enviroment vars
        cond: "test -f /tmp/test_env.py"
        script: |
         /tmp/test_env.py
        env: {TESTVAR: example-value} # set environment variables for the command

spot -p test-env.yml -v --dry

spot v1.16.0-ca4ade3-2024-04-27T19:58:38Z
dry run - no changes will be made and no commands will be executed
[h1 192.168.1.42:22] run task "Some tests", commands: 1
[h1 192.168.1.42:22] run command "Testing enviroment vars"
[h1 192.168.1.42:22] > /bin/sh -c 'TESTVAR="example-value"; test -f /tmp/test_env.py'
[h1 192.168.1.42:22] ! command script /tmp/.spot-719631138223510784/spot-script4222649707
[h1 192.168.1.42:22] > #!/bin/sh
[h1 192.168.1.42:22] > set -e
[h1 192.168.1.42:22] > export TESTVAR="example-value"
[h1 192.168.1.42:22] > /tmp/test_env.py
[h1 192.168.1.42:22] > /bin/sh -c /tmp/.spot-719631138223510784/spot-script4222649707
[h1 192.168.1.42:22] completed command "Testing enviroment vars" {script: /bin/sh -c [multiline script]} (0s)
[h1 192.168.1.42:22] completed task "Some tests", commands: 1 (21ms)

If I call it in the command line works fine:

spot -p test-env.yml -v --dry --shell /bin/bash

spot v1.16.0-ca4ade3-2024-04-27T19:58:38Z
dry run - no changes will be made and no commands will be executed
[h1 192.168.1.42:22] run task "Some tests", commands: 1
[h1 192.168.1.42:22] run command "Testing enviroment vars"
[h1 192.168.1.42:22] > /bin/bash -c 'TESTVAR="example-value"; test -f /tmp/test_env.py'
[h1 192.168.1.42:22] ! command script /tmp/.spot-7313637980666303488/spot-script1822616870
[h1 192.168.1.42:22] > #!/bin/bash
[h1 192.168.1.42:22] > set -e
[h1 192.168.1.42:22] > export TESTVAR="example-value"
[h1 192.168.1.42:22] > /tmp/test_env.py
[h1 192.168.1.42:22] > /bin/bash -c /tmp/.spot-7313637980666303488/spot-script1822616870
[h1 192.168.1.42:22] completed command "Testing enviroment vars" {script: /bin/bash -c [multiline script]} (0s)
[h1 192.168.1.42:22] completed task "Some tests", commands: 1 (15ms)

umputun added a commit that referenced this issue Jun 5, 2024
This regression was introduced some time back and set the default SSH shell to /bin/sh. This setting is considered the highest priority in CLI overrides and consequently enforced /bin/sh even if a custom SSH shell was set in the playbook.
umputun added a commit that referenced this issue Jun 5, 2024
This regression was introduced some time back and set the default SSH shell to /bin/sh. This setting is considered the highest priority in CLI overrides and consequently enforced /bin/sh even if a custom SSH shell was set in the playbook.
@umputun
Copy link
Owner

umputun commented Jun 5, 2024

Thanks for the report. This unexpected regression has been fixed. The override for ssh_shell was incorrectly defaulted in the CLI parameters, causing /bin/sh to be forced on all the commands.

Please note - the issue was real, but you may not solely rely on the log to understand which shell was used. In the example above, it may show "/bin/sh -c /tmp/.spot-719631138223510784/spot-script4222649707" because it wraps multiline commands with /bin/sh. However, the actual shell set in the script itself will automatically be the correct one (#!/bin/bash) in your case.

You can also add something like echo "Interpreter: $SHELL" to your script command to verify which shell was actually used.

Pls, check it out (on master) and let me know if the issue was fixed for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants