2012-07-12 37 views
3

我有一個fabfile:--user =根似乎並不覆蓋面料env.user,怎麼來的?

env.user = 'deploy' 

def infra(): 
    """You need to use a user that can root itself, deploy cannot without a 
    password.""" 
    put('conf.d/etc/nginx/sites-available/www.foo.hk', 
     '/etc/nginx/sites-available/www.foo.hk', use_sudo=True) 
    sudo('nginx -s reload',) 

它在我奔跑像fab infra -Rservers

所以我想我可以用--user=root or -u root覆蓋用戶,當我運行fab infra --user=root但它仍然要求我輸入密碼。但是,如果我改變env.userenv.user = 'root'事實並非如此。我也可以使用設置上下文管理器,如:

def infra(user): 
    """You need to use a user that can root itself, deploy cannot without a 
    password.""" 
    with settings(user=user): 
     put('conf.d/etc/nginx/sites-available/www.foo.hk', 
      '/etc/nginx/sites-available/www.foo.hk', use_sudo=True) 
     sudo('nginx -s reload',) 

這有效,當我做fab infra:root -Rservers。很顯然,可以重寫該設置,但似乎我不能從正常的命令行標誌中獲取。難道我做錯了什麼?

+0

你運行的是什麼版本的面料? – Morgan 2012-07-12 17:25:52

回答

0

你已經有了一個ticket open for this,我也表現的例子還有更多像你這樣的表現在這裏。我的猜測是你不能在文件中預先設置env.user,因爲這是一個明確的硬編碼。