2014-09-12 80 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

相关问题