Setup Git on FreeBSD
2020-04-28This article describes how to setup a git server on freebsd without authentification for private use
Walktrough
First we'll install the required packages via pkg install:
- name: Installing (sta)git on "{{hostname}}"
pkgng:
name: git,stagit
state: present
This will also install a user for git and gitdaemon as well as corresponding groups.
Now, we'll create a directory under / where the git repositories will reside in the future.
- name: create repos directory {{ git_base_dir }}
file:
path: "{{ git_base_dir }}"
state: directory
mode: '0755'
recurse: yes
owner: git
group: git
For testing purposes and as a starting point for later maintenance (i.e. adding of new repositories), the following task creates a bare git repository.
- name: git init --bare {{ project }}
command: git init --bare {{ project }}
args:
chdir: "{{ git_base_dir }}"
become_user: git
There is no service for git daemon installed, thus we're using inted to piggyback git daemon:
- inetd: special flag indicating that daemon is executed under inted
- export-all: important otherwise you'll get a error about repo not available or not exported
- reuseaddr: don't wait for releasing the address if daemon will be restarted, just use the same
- base-path: for e.g. a /repos/foo.git becomes /foo.git during clone
- enable=receive-pack: without that you can only pull but are not allowed to push any changes
- name: enable git-daemon as inetd service
lineinfile:
path: /etc/inetd.conf
line: git stream tcp nowait git /usr/local/bin/git git daemon --inetd --verbose --export-all --reuseaddr --syslog --base-path=/repos --enable=receive-pack
As a last step, enable inted service during boot:
- name: enable inetd
lineinfile:
path: /etc/rc.conf
line: inetd_enable="YES"
Example
git clone git://example.conf/ansible.git