首页 > 解决方案 > Ansible Playbook 充当 Git 中间人

问题描述

我的情况是我正在从我的笔记本电脑上运行一个剧本来构建一个新的服务器,我需要从远程源克隆一个 repo。问题是我的新服务器和 GitServer 无法相互通信。

所以我的问题是,如何将我的笔记本电脑用作临时位置,以便我可以将存储库克隆到新服务器?例如,我可以从 GitHub 将 Git 克隆到我的笔记本电脑,然后从我的笔记本电脑在新服务器上进行 git 克隆吗?

  - name: Clone between Hosts Part 1
    git:
      repo: https://github.com/blah/blah.git
      dest: /my/laptop/var/tmp/

  - name: Clone between Hosts Part 2
    git:
      repo: /my/laptop/var/tmp/blah.git
      dest: /remote/server/directory/

这样的事情可能吗?将 repo 克隆到我的笔记本电脑,然后从我的笔记本电脑将其重新克隆到远程服务器上?

标签: gitansibleclone

解决方案


您可以使用本地操作将 repo 克隆到本地笔记本电脑:

 - name: check out a git repository
    local_action: git repo=git://foosball.example.org/path/to/repo.git dest=/local/path

比您可以使用syncronizecopy将文件获取到您的服务器。

从远程服务器到本地机器的 Git 克隆有点困难,因为远程服务器必须能够访问本地笔记本电脑。所以更容易将文件从本地复制到远程服务器。


推荐阅读