Repository navigation
|
Hi! How do I get the isn't working. |
Replies: 2 comments 1 reply
|
If you get From your list: If you just want the user the deploy is running as, ask the remote: from pyinfra import host
from pyinfra.facts.server import User
remote_user = host.get_fact(User) # runs `echo $USER` on the hostOr set Docs: https://docs.pyinfra.com/en/latest/inventory-data.html (see "Connecting with Data"). Where does your user come from right now, the inventory, |
|
Hey, Then you can retrieve its value by using the snippet (Notice that the variable name |
host.data.get("ssh_user")is the right call, and it does work when pyinfra actually knows the user. It returns the value ifssh_useris set in the inventory (("myhost", {"ssh_user": "deploy"})), in group data (group_data/all.pywithssh_user = "deploy"), or with--user/--ssh-useron the CLI, which gets put into override data.host.data.ssh_userandhost.connector.data.get("ssh_user")give the same value. I checked all three on pyinfra 3.10 by building anInventory+Statethrough the API.If you get
None, you never set it in pyinfra. The username then comes from~/.ssh/config(User, which pyinfra's SSH client reads when it connects) or from your local username. None of that is written bac…