Using sudo operation

The syntax for the Fabric sudo operation is as follows:

sudo(command, shell=True, pty=True, combine_stderr=True, user=None, quiet=False, warn_only=False, stdout=None, stderr=None, group=None)

This operation can be considered another wrapper around the run() command. However, the sudo operation will run the command with the root username by default regardless of the username used to execute the fabfile. Also it contains a user argument which could be used to run the command with a different username. Also, the user argument executes the command with a specific UID, while the group argument defines the GID:

def sudo_ops():    sudo("whoami") #it should print the root even if you use another account

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.