Search code examples
gitansibleclone

Ansible Playbook acting as a Git Middle Man


The situation I have is that I'm running a playbook from my laptop to build a new server and I need to clone a repo from a remote source. The problem is that my New Server and GitServer cannot talk to one another.

So my question is, how can I utilize my Laptop as a temporary location so I can clone repos to a new server? For example, can I Git Clone from GitHub to my laptop and then git clone on the New server from my laptop?

  - 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/

Is something like this possible? Cloning the repo to my laptop, then recloning it on the remote server from my laptop?


Solution

  • You can use a local action to clone the repo to your local laptop:

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

    Than you can use syncronize or copy to get the files to your server.

    A Git clone from the remote server to your local maschine is a bit difficult, because your remote server must have access to your local laptop. So it's easier to copy the files from local to the remote server.