Commit 2dba707a authored by Muhammad Umair Khan's avatar Muhammad Umair Khan
Browse files

Update deployment configuration for robust execution

- Pin pyinfra to version 3.10.0 in setup.sh for consistency
- Fix sudo credential mapping by setting both sudo_password and _sudo_password in config_helpers.py for PyInfra 3 compatibility
- Prevent false positives during passwordless sudo validation by adding the -k flag and isolating stdin
- Add retry mechanism to Helm snap installation to gracefully handle transient network errors
parent d81746f3
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -122,13 +122,13 @@ def get_k8s_inventory():
        import subprocess
        for host_addr, ssh_user in nodes:
            if host_addr == "@local":
                cmd = ["sudo", "-n", "true"]
                cmd = ["sudo", "-n", "-k", "true"]
                err_msg = "[ERROR] Localhost (@local) requires a password for sudo, but no password was entered."
            else:
                cmd = ["ssh", "-o", "BatchMode=yes", "-o", "ConnectTimeout=5", f"{ssh_user}@{host_addr}", "sudo", "-n", "true"]
                cmd = ["ssh", "-o", "BatchMode=yes", "-o", "ConnectTimeout=5", f"{ssh_user}@{host_addr}", "sudo", "-n", "-k", "true"]
                err_msg = f"[ERROR] Remote host {host_addr} ({ssh_user}) requires a password for SSH or sudo, but no password was entered."

            res = subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
            res = subprocess.run(cmd, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
            if res.returncode != 0:
                print(f"\033[91m{err_msg}\033[0m")
                prompted = getpass.getpass(f"Enter SSH/sudo password for {label} ({host_addr}): ").strip()
@@ -148,7 +148,7 @@ def get_k8s_inventory():

    # 3. Build PyInfra host tuples
    def _build_host_tuple(host_addr, ssh_user, pw):
        data = {"ssh_user": ssh_user, "sudo_password": pw}
        data = {"ssh_user": ssh_user, "sudo_password": pw, "_sudo_password": pw}
        if host_addr != "@local" and pw:
            data["ssh_password"] = pw
        return (host_addr, data)
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ pip install --upgrade pip >/dev/null 2>&1
# Install pyinfra if not already installed
if ! command -v pyinfra >/dev/null 2>&1; then
    log_info "Installing pyinfra..."
    pip install pyinfra python-dotenv ruamel.yaml PyYAML
    pip install pyinfra==3.10.0 python-dotenv ruamel.yaml PyYAML
    log_success "pyinfra installed successfully."
else
    log_success "pyinfra is already installed in the virtual environment."
+3 −1
Original line number Diff line number Diff line
@@ -7,5 +7,7 @@ snap.package(
    channel="3.7/stable",
    classic=True,
    present=True,
    _sudo=True
    _sudo=True,
    _retries=3,
    _retry_delay=5
)