from fabric import Connection as connection, task @task def executeTask(ctx): with connection(host=dev_server, user=myuser) as c: c.run(‘sudo su – dev_user’) Place this code in a file called fabfile.py and run it by executing this command from your command-line fab executeTask. share.
10/29/2013 · Is it any way to imitate sudo su – user_name command and then execute commands I needed? Tried run and sudo and unfortunately there is no way to make it. … This is more mailing list fodder than an actual issue with fabric – going to close as such. bitprophet closed this Aug 4, 2014. This was referenced Jan 2, 2015. Add a login_shell option …
Using Fabric I created a simple script that basically runs commands thru SSH on some remote systems. Some of the commands require me to sudo su .
# Defaults env_reset # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL) ALL # Allow members of group sudo to execute any command after they have # provided their password # (Note that later entries override this, so you might need to move # it further down) % sudo ALL …
Got it. Only what I’m allowed to do as superuser is sudo su – user2, if I try sudo it won’t pass. And doing sudo (‘ su – user2’) will try to execute this sudo -S -p which is not possible for me. fabric is not specific enough 🙂 on some points smarber Feb 28 ’13 at 15:14, 1/31/2014 · Along with run, the most widely used Fabric command is probably sudo . It allows the execution of a given set of commands and arguments with sudo (i.e. superuser ) privileges on the remote host. If sudo command is used with an explicitly specified user, the execution will happen not as root but another (i.e. UID 1010).
where user is your sudo user and some_command the command you want to run with fabric, then on the fabric script run sudo it with shell=False: sudo(‘some_command’, shell=False) this works for me, You can use the fabric method sudo instead of run that runs a shell command on a remote host, with superuser privileges. For example, these commands are executed using sudo : sudo(~/install_script.py) sudo(mkdir /var/www/new_docroot, user=www-data) sudo(ls /home/jdoe, user=1001) result =