2015-09-07 60 views
5

我想從使用Ansible 1.9.3(OSX)和https連接的Bitbucket克隆私人git存儲庫。我將我的密碼存儲在剪貼板中,並在要求提供密碼時使用粘貼。下面的命令要求我提供密碼兩次或三次(不規則,一次也沒有,從來沒有超過三個):使用Ansible從Bitbucket克隆git repo - 詢問密碼兩三次

[~/devops]# ansible localhost -c local -m git -a "repo=https://[email protected]/techraf/ansible-local.git dest=~/devops/ansible-local" 
Password for 'https://[email protected]': 
Password for 'https://[email protected]': 
Password for 'https://[email protected]': 
localhost | success >> { 
    "after": "445dfaf39a6245bc30149dd722b1a17d0e56ba55", 
    "before": null, 
    "changed": true 
} 

[~/devops]# 

上可嘗試立即導致錯誤remote: Invalid username or password提供了不正確的密碼,所以打字錯誤是出的問題。 -vvv選項不提示。延遲輸入密碼似乎不會影響行爲。

爲什麼我問了幾次以及爲什麼次數不同?

回答

5

Ansible git模塊不僅僅是克隆。它也可以更新現有的本地存儲庫,使用子模塊等(http://docs.ansible.com/ansible/git_module.html

我的猜測是它正在執行多個操作,其中每個操作都需要訪問遠程BitBucket回購。看git module's source code表明,即使只是clone步驟,它也會用不同的參數執行git二進制。這可能是在這裏發生的 - 取決於你是否已經克隆了repo,命令的數量可能會有所不同,並且與本地repo交互的每個命令都會再次請求密碼。

要解決這個問題,你應該考慮在目標機器上設置一個Git credential helper。在最簡單的情況下,您可以使用cache實現,該實現會將您的密碼緩存幾分鐘。在這種情況下輸入一次就足夠了。

+0

現貨!克隆到新存儲庫時需要三次,而目標存儲庫已經存在兩次。配置'''''git config --global credential.helper'cache''''確實可以防止附加的密碼請求。謝謝。 – techraf

+0

不客氣,很高興聽到它的工作。 – nwinkler