-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to context.put
a file with sudo
.
#1750
Comments
This is documented in http://docs.fabfile.org/en/latest/upgrading.html#id15. There appears to be no good single-command replacement for this – e.g. you can't use Here's what I've been using to do the temp-file dance, which is arguably what you should always be doing anyway to avoid leaving files with unintended permissions: def sudo_install(connection, source, dest, *, owner='root', group='root', mode='0600'):
"""
Helper which installs a file with arbitrary permissions and ownership
This is a replacement for Fabric 1's `put(…, use_sudo=True)` and adds the
ability to set the expected ownership and permissions in one operation.
"""
mktemp_result = connection.run('mktemp', hide='out')
assert mktemp_result.ok
temp_file = mktemp_result.stdout.strip()
try:
connection.put(source, temp_file)
connection.sudo(f'install -o {owner} -g {group} -m {mode} {temp_file} {dest}')
finally:
connection.run(f'rm {temp_file}') Invoked as e.g. @task
def install_mount_status_monitor(conn):
sudo_install(conn, override_file, "/etc/systemd/system/mount_status_monitor.service.d/override.conf") |
Is this the expected route to use when trying to copy a local file to a remote server outside of the user's home directory? What is the intended way to use Fabric and copy a file into, say, /etc/nginx/? I'm trying to find the fabric2 way of using |
@geoffrey-eisenbarth At the moment there's no "blessed" approach for this - see the bit about sudo under http://www.fabfile.org/upgrading.html#file-transfer For now, you'd want to do something basic like c.put("path/to/local/nginx.conf") # implicit to remote $HOME
c.sudo("mv nginx.conf /etc/nginx/") # again implicitly with a CWD of $HOME |
In v2, the
use_sudo=True
parameter doesn't exist anymore.If I try to copy a file on the remote host, here is what I get:
The text was updated successfully, but these errors were encountered: