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

Deploying to SSH aliases is no longer possible #1170

Closed filips123 closed 1 month ago

filips123 commented 1 month ago

Describe the bug

In pyinfra 2.7, it was possible to run a deploy to a SSH alias defined in ~/.ssh/config file, like this:

pyinfra server-alias deploy.py

In pyinfra 3.0.2, this is no longer possible, and fails with:

server-alias is neither an inventory file, a (list of) hosts or connectors nor refers to a python module

To Reproduce

Add an alias to your ~/.ssh/config:

Host server-alias
    HostName example.com
    User user
    Port 22

Try to deploy to that alias:

pyinfra server-alias deploy.py

Expected behavior

pyinfra should detect that this is a host alias and use it to connect to the server.

Meta

    System: Windows
      Platform: Windows-11-10.0.22631-SP0
      Release: 11
      Machine: AMD64
    pyinfra: v3.0.2
    Executable: E:\Projects\GimVicUrnik\venv\Scripts\pyinfra.exe
    Python: 3.12.4 (CPython, MSC v.1940 64 bit (AMD64))
simonhammes commented 1 month ago

Can you try @ssh/server-alias?

filips123 commented 1 month ago

Yes, that works. Is it possible to add back support for aliases without @ssh/ prefix, as it was supported in previous versions and is slightly shorter to type?

I guess that the problem is that pyinfra now checks if the hostname resolves correctly, which SSH aliases don't. I didn't check how it was handled in previous versions and why the check is needed. Maybe it can be extended to support SSH aliases or just removed?

simonhammes commented 1 month ago

I'm very new to pyinfra, so I can't answer all of your questions :sweat_smile:

You might be able to use something like this to check if the provided alias resolves (e.g. in case socket.getaddrinfo() raises).

simonhammes commented 1 month ago

You might be able to use something like this to check if the provided alias resolves (e.g. in case socket.getaddrinfo() raises).

I'll give this a go.