You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because 1:1 native equivalent with what is actually run on the system.
For inventory management, pyinfra starts paying off.
Details
Shell + SSH advantages:
Shines because 1:1 equivalent with what is actually run on the system.
A few orders of magnitude less code.
Shell scripts are preferred for local dev setup.
Instant ad-hoc management using ssh.sh
If you feel the need to rewrite in Python, you're probably over-engineering.
Editors are much better equipped to syntax highlight pure bash than "bash in python strings".
Shell + SSH disadvantages:
Need to input password for sudo once per run if your script requires sudo.
On the bright side, it is not stored anywhere or viewable in ps -aux like in Pyinfra.
Seperate commands for serial or parallel execution. May be an issue with a lot of servers.
Doesn't always stop on fail with child scripts.
Debugging sucks more.
Shell + SSH Notes:
π Re-sync can be automated by rsync then rm scripts directory for every command.
Pyinfra advantages:
No script sync whatsoever, just change the file and run directly. Each line is a seperate ssh connection.
Can upload files mid-script because "Each line is a seperate ssh connection."
No need to enter sudo for your password every time. Passed via env var, used with SUDO_ASKPASS
No fiddling with single or double quotes. Python allows you to use triple quotes.
Syntax check (logic flow only, no shell) happens before you run the script.
Pyinfra disadvantages:
Pyinfra operations need to be written seperately for apt, rpm, windows, etc. anyway. There's no unification.
Shell syntax highlighting is crap because it is in strings.
You're writing shell anyway, wrapped in python.
sudo in uploaded .sh scripts does not work because pyinfra cannot prompt for sudo inside of a script, only for the parent command itself. Pretty much delegates .sh to local only.
π Pyinfra is still over-engineered af, but you can simplify things by combining group_data into the hosts files, and using the scripts/ + servers/ pattern and aliasing stuff like server.shell() to run()
Output tends to be hidden unless you use -vvv or another