This guide provides a full Ansible playbook to deploy cgit on Debian 10+, Ubuntu LTS, and RHEL 9+ compatible hosts using traditional CGI installation.
- name: Deploy cgit
hosts: cgit
become: true
vars:
cgit_version: 1.2.3
cgit_src_dir: /opt/cgit-src
cgit_cache: /var/cache/cgit
cgit_git_path: /srv/git
tasks:
- name: Install dependencies on Debian/Ubuntu
apt:
name:
- git
- build-essential
- liblua5.3-dev
- apache2
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install dependencies on RHEL family
dnf:
name:
- git
- gcc
- make
- lua-devel
- httpd
state: present
when: ansible_os_family == "RedHat"
- name: Clone cgit source
git:
repo: https://git.zx2c4.com/cgit/
dest: "{{ cgit_src_dir }}"
version: "v{{ cgit_version }}"
- name: Build cgit
command: make prefix=/usr
args:
chdir: "{{ cgit_src_dir }}"
creates: "{{ cgit_src_dir }}/cgit"
- name: Install cgit
command: make install
args:
chdir: "{{ cgit_src_dir }}"
creates: /var/www/cgi-bin/cgit.cgi
- name: Create cache directory
file:
path: "{{ cgit_cache }}"
state: directory
owner: www-data
group: www-data
mode: "0755"
when: ansible_os_family == "Debian"
- name: Create cache directory (RHEL)
file:
path: "{{ cgit_cache }}"
state: directory
owner: apache
group: apache
mode: "0755"
when: ansible_os_family == "RedHat"
- name: Create cgit configuration
copy:
dest: /etc/cgitrc
mode: "0644"
content: |
virtual-root=/
cache-root={{ cgit_cache }}
scan-path={{ cgit_git_path }}
enable-http-clone=1
remove-suffix=1
strict-export=1
- name: Create git repository directory
file:
path: "{{ cgit_git_path }}"
state: directory
mode: "0755"
- name: Enable Apache CGI module
apache2_module:
name: cgi
state: present
when: ansible_os_family == "Debian"
notify: restart apache
- name: Enable Apache CGI module (RHEL)
command: a2enmod cgi
when: ansible_os_family == "RedHat"
notify: restart apache
- name: Write Apache configuration for cgit
copy:
dest: /etc/apache2/sites-available/cgit.conf
mode: "0644"
content: |
<VirtualHost *:80>
ServerName git.example.com
DocumentRoot /var/www/cgit
<Directory "/var/www/cgit">
Options +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex cgit.cgi
</Directory>
</VirtualHost>
when: ansible_os_family == "Debian"
notify: restart apache
- name: Enable cgit site
command: a2ensite cgit.conf
when: ansible_os_family == "Debian"
notify: restart apache
handlers:
- name: restart apache
service:
name: apache2
state: restarted
when: ansible_os_family == "Debian"
- name: restart apache (RHEL)
service:
name: httpd
state: restarted
when: ansible_os_family == "RedHat"
/etc/cgitrcAny questions?
Feel free to contact us. Find all contact information on our contact page.