2014-09-12 77 views
0

以下是我試圖運行的操作手冊。無法將多個存儲庫結帳到單個目錄

--- 
- hosts: all 
    sudo : true 
    sudo_user : ganesh 

    tasks: 
    - name: git repo clone 
    git: repo=https://ganesh:[email protected]/myrepo/root-repo.git dest=/home/ganesh/rootrepo version=master recursive=no 
    git: repo=https://ganesh:[email protected]/myrepo/subrepo1.git dest=/home/ganesh/rootrepo/subrepo1 version=master recursive=no 
    git: repo=https://ganesh:[email protected]/myrepo/subrepo2.git dest=/home/ganesh/rootrepo/subrepo2 version=master recursive=no 
    git: repo=https://ganesh:[email protected]/myrepo/subrepo3.git dest=/home/ganesh/rootrepo/subrepo3 version=master recursive=no 

運行這個劇本後,我期待以下目錄結構。

 
rootrepo 
    - root repo contents 
    - subrepo1 
     - subrepo1 contents 
    - subrepo2 
     - subrepo2 contents 
    - subrepo3 
     - subrepo3 contents 

但只有一個回購協議,即,subrepo3,則執行劇本後下rootrepo目錄剩餘。其他一切都被刪除了。即使rootrepo內容正在被刪除。

 
rootrepo 
    - subrepo3 
     - subrepo3 contents 

爲什麼這樣呢?如何實現我期待的目錄結構?

+0

您應該使用[git的子模塊(http://www.git-scm.com/book/en/Git-Tools-Submodules) – keltar 2014-09-12 11:39:24

+0

感謝@keltar的回覆。有沒有辦法在ansible中執行這個git子模塊。 – 2014-09-12 12:24:59

回答

2

關於爲什麼這不是按照規定工作的解釋是Ansible戲劇被讀作yaml文件,而「tasks」是詞典列表。在你的情況下,你正在複製模塊「git」(字典中的一個鍵),因此最後一個獲勝。

做的正是你想要的打法之後將工作

--- 
- hosts: all 
    sudo : true 
    sudo_user : ganesh 

    tasks: 
    - name: git repo clone 
    git: repo=https://ganesh:[email protected]/myrepo/root-repo.git dest=/home/ganesh/rootrepo version=master recursive=no 
    - name: clone subrepos 
    git: repo=https://ganesh:[email protected]/myrepo/{{ item }}.git dest=/home/ganesh/rootrepo/{{ item }} version=master recursive=no 
    with_items: 
     - subrepo1 
     - subrepo2 
     - subrepo3 

雖然在一般,這不是一個好主意,有庫在其他庫簽出。 更有可能你想要做的是將subrepo {1,2,3}作爲子模塊添加到root-repo。

假設你已經提交對根倉庫的訪問權然後克隆它,然後運行。

git submodule add https://ganesh:[email protected]/myrepo/subrepo1.git subrepo1 
git submodule add https://ganesh:[email protected]/myrepo/subrepo2.git subrepo2 
git submodule add https://ganesh:[email protected]/myrepo/subrepo3.git subrepo3 

入住這些變化,然後在你的遊戲設置遞歸=真正當你結賬根repo.git

+0

謝謝@jarv。當我創建克隆sub-repos的獨立任務時它的工作。看起來你使用'submodule'和'recursive = true'的建議使得工作變得簡單,但是如果我想檢查根模塊和子模塊的不同分支,例如,根模塊的'master'分支和一些'dev'分支子模塊。 – 2014-09-15 06:36:42

相關問題