pyinfra-dev / pyinfra-dev/pyinfra

Nested operations do not support programmatic sudo

Open
#806 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
6k
Forks
548
Avg merge
7d 17h
Merged PRs (30d)
13

Description

Describe the bug

Trying to use nested operations which require programmatic sudo access throws AttributeError

UPDATE: perhaps this should just be that nested operations do not support custom config attributes(?)

To Reproduce

from pyinfra import config

config.USE_REMOTE_SUDO_PASSWORD = "something"

def callback():
    result = server.shell(
        commands=["cat foo"],
        _sudo=True,
        _use_sudo_password=config.USE_REMOTE_SUDO_PASSWORD
    )

def caller(vm_name):
    python.call(
        name="Execute callback function",
        function=callback,
    )

[server.foo] Unexpected error in Python callback: AttributeError("'Config' object has no attribute 'USE_REMOTE_SUDO_PASSWORD'",)

Expected behavior

I would expect a nested operation to support programmtic sudo access

Meta

  • Include output of pyinfra --support.
    System: Linux
      Platform: Linux-5.10.105-1-MANJARO-x86_64-with-glibc2.35
      Release: 5.10.105-1-MANJARO
      Machine: x86_64
    pyinfra: v2.1
    Executable: /home/user/workspace/something/venv/bin/pyinfra
    Python: 3.10.4 (CPython, GCC 11.2.0)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the nested python.call callback from the issue, focusing on server.shell with _sudo and _use_sudo_password=config.USE_REMOTE_SUDO_PASSWORD. Trace how configuration is exposed inside nested operations; done means the example no longer raises AttributeError and programmatic sudo works, or the supported limitation is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.