Fabric Sudo无密码解决方案

问题描述:

此问题与最佳做法有关。我正在使用Fabric运行部署脚本。我的部署用户部署需要sudo才能重新启动服务。因此,我正在使用Fabric中的sudo函数在脚本中运行这些命令。这可以正常工作,但在脚本执行期间提示输入密码。我不想在部署期间输入密码。这里的最佳做法是什么。我能想到的唯一解决方案是更改sudo权限,以使部署用户运行的命令不需要密码。

This question is about best practices. I'm running a deployment script with Fabric. My deployment user 'deploy' needs sudo to restart services. So I am using the sudo function from fabric to run these commands in my script. This works fine but prompts for password during script execution. I DON'T want to type a password during deployments. What's the best practice here. The only solution I can think of is changing the sudo permissions to not require password for the commands my deployment user runs. This doesn't seem right to me.

正如Bartek所建议的那样,为部署用户启用无密码sudo。在sudoers文件中。

As Bartek also suggests, enable password-less sudo for the deployment 'user' in the sudoers file.

类似的东西:

run('echo "{0} ALL=(ALL) ALL" >> /etc/sudoers'.format(env.user))