0
我想使用fabric在遠程機器上部署某些應用程序。爲此,我使用結構從VCS(bitbucket或github)檢索bash腳本並執行它。但是,我的腳本的第一步是將當前用戶添加到sudoers,所以我需要輸入密碼。Fabric運行bash腳本請求sudo密碼 - 如何發送此密碼
是否可以在fabfile或fab命令或....內發送此密碼?
的代碼的一部分:
的bash
sudo tee /etc/sudoers.d/$USER <<END
END
file=/usr/share/MyCompagny/mybashscript.sh
sudo touch $file
sudo echo 'blablabla' >> $file
sudo /bin/rm /etc/sudoers.d/$USER
sudo -k
fabfile
def deploy():
env.hosts = ['192.168.100.160']
source_folder = '/home/username/src'
branch = 'dev'
puts('Pulling changes from branch <{}>'.format(branch))
projects = ['data', 'report']
for project in projects:
current_path = os.path.join(source_folder, 'package.{}'.format(project))
with cd(current_path):
puts('Current path: {}'.format(current_path))
# Discard all pending changes
run('git checkout -- .')
# Checkout the right branch
run('git checkout {}'.format(branch))
# Pull changes
run('git pull origin_ssh {}'.format(branch))
puts('Install with bash script')
with cd(source_folder):
run('./mybashscript.sh')