運行Fabric(1.11.1)(Paramiko(1.16.0),Python(2.7.11))的最新版本,即時獲取最奇怪的錯誤,我做了一些概念驗證試試看。Fabric結構設置問題()
from fabric.api import run, sudo, task
from fabric.context_managers import settings
@task
def test():
print('regular run')
run('whoami')
print('regular sudo')
sudo('whoami')
print('sudo with user arg')
sudo('whoami', user='www-data')
with settings(user='www-data'):
print('run inside settings')
run('whoami')
輸出:
$ fab -f test.py -H [email protected]:2222 test
[[email protected]:2222] Executing task 'test'
regular run
[[email protected]:2222] run: whoami
[[email protected]:2222] out: vagrant # <--- good
[[email protected]:2222] out:
regular sudo
[[email protected]:2222] sudo: whoami
[[email protected]:2222] out: root # <--- good
[[email protected]:2222] out:
sudo with user arg
[[email protected]:2222] sudo: whoami
[[email protected]:2222] out: www-data # <--- good
[[email protected]:2222] out:
run inside settings
[[email protected]:2222] run: whoami
[[email protected]:2222] out: vagrant # <--- WHAT THE HECK!? this used to work
[[email protected]:2222] out:
Done.
做了什麼變化?或者我只是做錯了什麼?