Git 无法将多个存储库签出到单个目录

Git 无法将多个存储库签出到单个目录,git,ansible,Git,Ansible,下面是我试图运行的剧本 --- - hosts: all sudo : true sudo_user : ganesh tasks: - name: git repo clone git: repo=https://ganesh:mypassword@github.com/myrepo/root-repo.git dest=/home/ganesh/rootrepo version=master recursive=no git: repo=https://ga

下面是我试图运行的剧本

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

  tasks:
  - name: git repo clone
    git: repo=https://ganesh:mypassword@github.com/myrepo/root-repo.git dest=/home/ganesh/rootrepo version=master recursive=no
    git: repo=https://ganesh:mypassword@github.com/myrepo/subrepo1.git dest=/home/ganesh/rootrepo/subrepo1 version=master recursive=no
    git: repo=https://ganesh:mypassword@github.com/myrepo/subrepo2.git dest=/home/ganesh/rootrepo/subrepo2 version=master recursive=no
    git: repo=https://ganesh:mypassword@github.com/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 rootrepo -根回购内容 -子报告1 -子报告1内容 -次级报告2 -次级报告2内容 -子报告3 -子报告3内容 但在playbook执行后,根repo目录下只剩下一个repo,即subrepo3。其他所有内容都将被删除。甚至rootrepo内容也被删除了

rootrepo - subrepo3 - subrepo3 contents rootrepo -子报告3 -子报告3内容
为什么会这样?如何实现我所期望的目录结构?

关于为什么这不起作用的解释是,Ansible plays作为yaml文件读入,“任务”是一个字典列表。在您的例子中,您正在复制模块“git”(字典中的一个键),因此最后一个模块获胜

要想做你想做的事,下面这出戏就行了

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

  tasks:
  - name: git repo clone
    git: repo=https://ganesh:mypassword@github.com/myrepo/root-repo.git dest=/home/ganesh/rootrepo version=master recursive=no
  - name: clone subrepos
    git: repo=https://ganesh:mypassword@github.com/myrepo/{{ item }}.git dest=/home/ganesh/rootrepo/{{ item }} version=master recursive=no
    with_items:
      - subrepo1
      - subrepo2
      - subrepo3
但一般来说,在其他存储库中签出存储库不是一个好主意。 更可能的情况是将子repo{1,2,3}作为子模块添加到根repo

假设您拥有对根repo的提交访问权限,请将其克隆并运行

git submodule add https://ganesh:mypassword@github.com/myrepo/subrepo1.git subrepo1
git submodule add https://ganesh:mypassword@github.com/myrepo/subrepo2.git subrepo2
git submodule add https://ganesh:mypassword@github.com/myrepo/subrepo3.git subrepo3

签入这些更改,然后在签出root repo.git时签入播放集recursive=true,您应该使用Thank@keltar获得回复。有没有办法在ansible中执行这个git子模块。谢谢@jarv。当我为克隆子repo创建单独的任务时,它就起作用了。似乎您建议使用
子模块
recursive=true
使工作变得简单,但是如果我想为根模块和子模块检查不同的分支,即根模块的
主分支
和子模块的一些
开发分支,该怎么办。