Fabric: do everything as a specific user

My deployment of assembly and production is connected using keys by one user, a specific user, which is used in conjunction with the deployment and keys copied during the acceleration of the machine.

This deploy user has shared ssh keys that allow ssh to use any machine between them.

Now my fabric structure works as a Jenkins user.

How can I tell the fabric to do everything as a specific user ( deploy in this case)? Equivalent to sudo su deploy

I do not want to do prefix or with in every task. Rather, set a global variable.

Jenkins is in the wheel group and has sudo perms

+4
source share
1 answer

If I understand your question correctly, you want to execute commands as another user without using a prefix or using.

The sudo function accepts a user, which can be a global variable if you want.

From the docs:

 fabric.operations.sudo(command, shell=True, pty=True, combine_stderr=True, user=None, quiet=False, stdout=None, stderr=None) 

You can just call your tasks with

 sudo(command, user=sudouser) 

and install sudouser to "deploy" elsewhere.

Actually this is no different from using context:

 with settings(sudo_user=sudouser): sudo(command) 

In both cases, you can change this sudo_user globally.

+7
source

Source: https://habr.com/ru/post/1416074/


All Articles