pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

`--sudo` does not seem to work for nested operations

Open martingms opened this issue 1 year ago • 0 comments

First, thanks for working on this great project, it's a breath of fresh air in the otherwise dark world of config/server management!

Describe the bug

I'm running pyinfra with the --sudo flag, and basically all operations I call need sudo the way I've set it up. This works fine, except for operations that are run within a python.call-context. For those I have to add _sudo=True to make it work.

This happens both on 2.x and 3.x as far I can tell.

To Reproduce

Steps to reproduce the behavior, please include where possible:

key = server.shell(
    name="get wireguard private key", commands="cat /etc/wireguard/private"
)

def create_config():
    files.template(
        name="generate wireguard config",
        src=conf_template,
        dest="/etc/wireguard/foo.conf",
        user="root",
        group="root",
        mode="700",
        host=host,
        key=key.stdout,
        # FIXME: This should not have to be set explicitly.
        _sudo=True,
    )

python.call(name="provide key to wireguard config", function=create_config)

Expected behavior

I expect the files.template-operation to not need _sudo=True when pyinfra is called with the --sudo flag.

Meta

System: Linux
  Platform: Linux-6.1.0-21-amd64-x86_64-with-glibc2.36
  Release: 6.1.0-21-amd64
  Machine: x86_64
pyinfra: v3.0b4
Executable: /home/mg/foo/.venv/bin/pyinfra
Python: 3.11.2 (CPython, GCC 12.2.0)

martingms avatar Jun 27 '24 08:06 martingms