Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: how to init git bare repository and clone it to the same machine?

I would like to ask you how it is possible to implement such a case using Ansible.

My main goal is to nit git bare repository and clone it to the same machine (/var/www). My usual steps were:

1) git init —bare (running in /git/project-name)

2) git clone /git/project-name —no-hardlinks (running in в /var/www)

When I am willing to do this case using Ansible, then I cant implement the first step -- initialization if an empty git bare repository.

Ansible git module requires that 'repo' param should be filled with repository address, but how I can define it if I am just creating one?

git: repo=?? dest=/git/project-name bare=yes

like image 362
Ivar Mahhonin Avatar asked Sep 13 '25 04:09

Ivar Mahhonin


1 Answers

Here is a sample playbook for setting up a git server with a new bare repo:

---
- hosts: git.example.org
  become: true
  tasks:
    - user:
        name: git
        shell: /usr/bin/git-shell
        home: /srv/git

    - authorized_key:
        user: git
        state: present
        key: https://github.com/myuser.keys

    - command: git init --bare /srv/git/myrepo.git
      args:
        creates: /srv/git/myrepo.git/HEAD
      become_user: git

If you've already got a git user set up on your server, then you only need to focus on the command task. Enjoy!

like image 133
bonh Avatar answered Sep 15 '25 19:09

bonh