pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.85k stars 374 forks source link

`_shell_executable=None` is ignored in inventory #1064

Closed vojta001 closed 6 months ago

vojta001 commented 7 months ago

Describe the bug

Since #724 we can use --shell-executable None in CLI to make pyinfra not explicitly specify a shell (crucial for non-POSIX targets). I struggle to opt in for the same behavior using the inventory file only.

To Reproduce

inventory.py:

test = [
    ("example.tld", {"_shell_executable": None, "ssh_user": "root"})
]
pyinfra -vvv inventory.py exec date

The output is

--> Loading config...

--> Loading inventory...

--> Connecting to hosts...
    [example.tld] Connected
    [example.tld] Ready: shell

--> Proposed changes:
    Groups: test / inventory
    [example.tld]   Operations: 1   Change: 1   No change: 0

--> Beginning operation run...
--> Starting operation: Server/Shell (date)
[example.tld] >>> sh -c date
[example.tld] Sun Feb  4 11:17:36 CET 2024
    [example.tld] Success

--> Results:
    Groups: test / inventory
    [example.tld]   Changed: 1   No change: 0   Errors: 0

Compare it with

pyinfra --shell-executable None -vvv inventory.py exec date

and its output


--> Loading inventory...

--> Connecting to hosts...
    [example.tld] Connected
    [example.tld] Ready: shell

--> Proposed changes:
    Groups: inventory / test
    [example.tld]   Operations: 1   Change: 1   No change: 0

--> Beginning operation run...
--> Starting operation: Server/Shell (date)
[example.tld] >>> date
[example.tld] Sun Feb  4 11:17:59 CET 2024
    [example.tld] Success

--> Results:
    Groups: inventory / test
    [example.tld]   Changed: 1   No change: 0   Errors: 0

It's the [example.tld] >>> sh -c date vs. [example.tld] >>> date.

Meta

Fizzadar commented 6 months ago

Hi @vojta001, thank you for reporting this. I've pushed a fix (unfortunately messed up the commit here) in https://github.com/pyinfra-dev/pyinfra/commit/8177f500d60a650313f20f2f4cce8f313d41e70c and just released that in v2.9.1. Would you be able to retry to confirm this is fixed?

Fizzadar commented 6 months ago

Fixed, cherry picked into v3 branch.

vojta001 commented 6 months ago

@Fizzadar Thank you for fixing this and sorry for the long delay to test the patch. I can now confirm the issue is gone.

Fizzadar commented 6 months ago

@vojta001 no worries at all appreciate you checking in 🙏