Skip to content

Add _sudo_set_home=True global argument to disable setting sudo home #1205

@DrSensor

Description

@DrSensor

Is your feature request related to a problem? Please describe

Discussed in #1204

Originally posted by DrSensor September 14, 2024
Hi, how to disable -H/--set-home flag when using _sudo=True?

a bit of context

# group_data/local.py

_sudo = True
_preserve_sudo_env = True
# deploy.py

from pyinfra.operations.server import shell, packages

packages(["direnv"]) # run as root

# I want to write the output to /home/$USER/... ; not /root/...
shell(["direnv hook fish > ~/.config/fish/conf.d/direnv.fish"])

after some inspection with pyinfra --debug inventory.py deploy.py

[pyinfra.connectors.local] --> Running command on localhost: env SUDO_ASKPASS=/tmp/pyinfra-sudo-askpass-vQ3t4mfcxJrY *** sudo -H -A -k -E sh -c 'direnv hook fish > ~/.config/fish/conf.d/direnv.fish'
[pyinfra.connectors.util] --> Waiting for exit status...
[pyinfra.connectors.util] --> Command exit status: 1

I notice it use -H

Describe the solution you'd like

I propose to add global argument _sudo_always_set_home1 where the default is True (for backward compatibility)

with this change, the group_data would be

# group_data/local.py

_sudo = True
_preserve_sudo_env = True
+ _sudo_always_set_home = False

Footnotes

  1. /etc/sudoers has an option called always_set_home

Metadata

Metadata

Assignees

No one assigned

    Labels

    connectorsConnector issues - builtin integrations with other tools.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions