summaryrefslogtreecommitdiffstats
path: root/roles/cgit
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2026-07-07 17:13:55 +0200
committerAhmed Abdelhalim <[email protected]>2026-07-07 17:16:46 +0200
commitd3cb7d3f393a1a0088e2da57da500c93a0220459 (patch)
treefffbfc46cbb1e33efa42a764cd3e024725010cf7 /roles/cgit
parent4d42a2b0950882bf63380a08c90007970c38b4ce (diff)
Add cgit role with testing of molecule service
Diffstat (limited to 'roles/cgit')
-rw-r--r--roles/cgit/defaults/main.yml8
-rw-r--r--roles/cgit/handlers/main.yml6
-rw-r--r--roles/cgit/meta/argument_specs.yml32
-rw-r--r--roles/cgit/meta/main.yml11
-rw-r--r--roles/cgit/tasks/main.yml58
-rw-r--r--roles/cgit/templates/cgit.nginx.conf.j219
-rw-r--r--roles/cgit/templates/cgitrc.j221
7 files changed, 155 insertions, 0 deletions
diff --git a/roles/cgit/defaults/main.yml b/roles/cgit/defaults/main.yml
new file mode 100644
index 00000000..5acf53fb
--- /dev/null
+++ b/roles/cgit/defaults/main.yml
@@ -0,0 +1,8 @@
+---
+cgit_hostname: "git.example.com"
+cgit_port: 80
+cgit_repos_dir: "/srv/git"
+cgit_title: "git"
+cgit_description: "personal git repositories"
+cgit_clone_prefix: "https://{{ cgit_hostname }}"
+cgit_ssh_user: "git"
diff --git a/roles/cgit/handlers/main.yml b/roles/cgit/handlers/main.yml
new file mode 100644
index 00000000..d4481590
--- /dev/null
+++ b/roles/cgit/handlers/main.yml
@@ -0,0 +1,6 @@
+---
+- name: "Restart nginx"
+ become: true
+ ansible.builtin.service:
+ name: nginx
+ state: restarted
diff --git a/roles/cgit/meta/argument_specs.yml b/roles/cgit/meta/argument_specs.yml
new file mode 100644
index 00000000..e0fa14d5
--- /dev/null
+++ b/roles/cgit/meta/argument_specs.yml
@@ -0,0 +1,32 @@
+---
+argument_specs:
+ main:
+ options:
+ cgit_hostname:
+ type: "str"
+ description: "Public hostname for cgit (e.g. git.example.com)"
+ default: "git.example.com"
+ cgit_port:
+ type: "int"
+ description: "Port nginx listens on"
+ default: 80
+ cgit_repos_dir:
+ type: "str"
+ description: "Directory containing bare git repositories"
+ default: "/srv/git"
+ cgit_title:
+ type: "str"
+ description: "cgit index page title"
+ default: "git"
+ cgit_description:
+ type: "str"
+ description: "cgit index page description"
+ default: "personal git repositories"
+ cgit_clone_prefix:
+ type: "str"
+ description: "Clone URL prefix shown in cgit UI"
+ default: "https://{{ cgit_hostname }}"
+ cgit_ssh_user:
+ type: "str"
+ description: "System user for SSH git push access"
+ default: "git"
diff --git a/roles/cgit/meta/main.yml b/roles/cgit/meta/main.yml
new file mode 100644
index 00000000..3b5e8d42
--- /dev/null
+++ b/roles/cgit/meta/main.yml
@@ -0,0 +1,11 @@
+---
+dependencies: []
+galaxy_info:
+ author: "a14m"
+ description: "Install and configure cgit git web viewer"
+ license: "MIT"
+ min_ansible_version: "2.18"
+ platforms:
+ - name: "Alpine"
+ versions:
+ - "all"
diff --git a/roles/cgit/tasks/main.yml b/roles/cgit/tasks/main.yml
new file mode 100644
index 00000000..663534ec
--- /dev/null
+++ b/roles/cgit/tasks/main.yml
@@ -0,0 +1,58 @@
+---
+- name: "Install packages"
+ become: true
+ ansible.builtin.package:
+ name:
+ - cgit
+ - nginx
+ - fcgiwrap
+ - openssh
+ state: present
+
+- name: "Create git user"
+ become: true
+ ansible.builtin.user:
+ name: "{{ cgit_ssh_user }}"
+ shell: "/usr/bin/git-shell"
+ home: "{{ cgit_repos_dir }}"
+ create_home: true
+ system: true
+
+- name: "Create repos directory"
+ become: true
+ ansible.builtin.file:
+ path: "{{ cgit_repos_dir }}"
+ state: directory
+ owner: "{{ cgit_ssh_user }}"
+ group: "{{ cgit_ssh_user }}"
+ mode: "0755"
+
+- name: "Deploy cgitrc"
+ become: true
+ ansible.builtin.template:
+ src: "cgitrc.j2"
+ dest: "/etc/cgitrc"
+ owner: "root"
+ group: "root"
+ mode: "0644"
+
+- name: "Deploy nginx config"
+ become: true
+ ansible.builtin.template:
+ src: "cgit.nginx.conf.j2"
+ dest: "/etc/nginx/http.d/cgit.conf"
+ owner: "root"
+ group: "root"
+ mode: "0644"
+ notify: "Restart nginx"
+
+- name: "Enable and start services"
+ become: true
+ ansible.builtin.service:
+ name: "{{ item }}"
+ enabled: true
+ state: started
+ loop:
+ - nginx
+ - fcgiwrap
+ - sshd
diff --git a/roles/cgit/templates/cgit.nginx.conf.j2 b/roles/cgit/templates/cgit.nginx.conf.j2
new file mode 100644
index 00000000..14256054
--- /dev/null
+++ b/roles/cgit/templates/cgit.nginx.conf.j2
@@ -0,0 +1,19 @@
+server {
+ listen {{ cgit_port }};
+ listen [::]:{{ cgit_port }};
+
+ server_name {{ cgit_hostname }};
+
+ root /usr/share/webapps/cgit;
+
+ try_files $uri @cgit;
+
+ location @cgit {
+ fastcgi_pass unix:/run/fcgiwrap/fcgiwrap.sock;
+ fastcgi_param SCRIPT_FILENAME /usr/lib/cgit/cgit.cgi;
+ fastcgi_param PATH_INFO $uri;
+ fastcgi_param QUERY_STRING $args;
+ fastcgi_param HTTP_HOST $server_name;
+ include fastcgi_params;
+ }
+}
diff --git a/roles/cgit/templates/cgitrc.j2 b/roles/cgit/templates/cgitrc.j2
new file mode 100644
index 00000000..a23e2d0b
--- /dev/null
+++ b/roles/cgit/templates/cgitrc.j2
@@ -0,0 +1,21 @@
+css=/cgit/cgit.css
+logo=/cgit/cgit.png
+
+virtual-root=/
+
+repo.group=personal
+
+root-title={{ cgit_title }}
+root-desc={{ cgit_description }}
+
+clone-prefix={{ cgit_clone_prefix }}
+
+enable-index-links=1
+enable-log-filecount=1
+enable-log-linecount=1
+enable-blame=1
+enable-tree-linenumbers=1
+
+max-stats=year
+
+scan-path={{ cgit_repos_dir }}