Repository navigation
v0.5.0 - Sudo Support
Added
- Sudo support for privileged operations - The OrbStack connector now handles PyInfra's
sudoandsudo_userarguments, enabling operations that require elevated privileges - Safe command quoting - Uses
shlex.quote()for proper handling of commands with special characters, quotes, and spaces - Comprehensive test coverage - 9 new sudo-specific unit tests covering all command types (string commands, StringCommand objects, and lists)
Installation
pip install pyinfra-orbstack==0.5.0
# or
uv pip install pyinfra-orbstack==0.5.0Usage Example
from pyinfra.operations import apt, server
# Run privileged commands
server.shell(
name="Remove lock files",
commands="rm -f /var/lib/dpkg/lock",
_sudo=True,
)
# Run as specific user
server.shell(
name="Run as postgres",
commands="whoami",
_sudo=True,
_sudo_user="postgres",
)
# Package operations with sudo
apt.packages(
name="Install nginx",
packages=["nginx"],
_sudo=True,
)Technical Details
The sudo implementation:
- Applies the
-Hflag for proper HOME directory handling (matching PyInfra's SSH connector) - Supports
_sudo_userparameter for running commands as specific users - Handles all command types: plain strings, PyInfra
StringCommandobjects, and lists - Properly quotes commands to safely handle special characters