From 421d03ba5446415bfe831a8618ff8238fd0c382c Mon Sep 17 00:00:00 2001 From: Ahmed AbdelHalim Date: Fri, 17 Jul 2026 15:40:22 +0200 Subject: Refactor proxy setup on cgit to simplify setup --- configure.yml | 2 +- group_vars/homelab.yml | Bin 4347 -> 4326 bytes host_vars/git.home.arpa.yml | Bin 569 -> 606 bytes molecule/git/converge.yml | 11 -------- molecule/git/molecule.yml | 11 -------- roles/cgit/defaults/main.yml | 1 - roles/cgit/handlers/main.yml | 14 ---------- roles/cgit/meta/argument_specs.yml | 10 +------ roles/cgit/tasks/main.yml | 46 -------------------------------- roles/cgit/templates/cgit.caddy.j2 | 5 ---- roles/cgit/templates/cgit.nginx.conf.j2 | 28 ------------------- roles/proxy/defaults/main.yml | 2 -- roles/proxy/meta/argument_specs.yml | 8 ------ roles/proxy/meta/main.yml | 20 -------------- roles/proxy/tasks/main.yml | 4 --- service.yml | 2 +- 16 files changed, 3 insertions(+), 161 deletions(-) delete mode 100644 roles/cgit/templates/cgit.caddy.j2 delete mode 100644 roles/cgit/templates/cgit.nginx.conf.j2 delete mode 100644 roles/proxy/defaults/main.yml delete mode 100644 roles/proxy/meta/argument_specs.yml delete mode 100644 roles/proxy/meta/main.yml delete mode 100644 roles/proxy/tasks/main.yml diff --git a/configure.yml b/configure.yml index 918812a6..540a51f4 100644 --- a/configure.yml +++ b/configure.yml @@ -90,7 +90,7 @@ - role: "vim" - role: "wireguard" - role: "gateway" - - role: "proxy" + - role: "caddy" - role: "wg_portal" - role: "pihole" - role: "prometheus" diff --git a/group_vars/homelab.yml b/group_vars/homelab.yml index ffc5eb07..cba875ac 100644 Binary files a/group_vars/homelab.yml and b/group_vars/homelab.yml differ diff --git a/host_vars/git.home.arpa.yml b/host_vars/git.home.arpa.yml index 99758953..e835dee9 100644 Binary files a/host_vars/git.home.arpa.yml and b/host_vars/git.home.arpa.yml differ diff --git a/molecule/git/converge.yml b/molecule/git/converge.yml index 8354d3ce..906de734 100644 --- a/molecule/git/converge.yml +++ b/molecule/git/converge.yml @@ -1,20 +1,9 @@ --- -- name: "Proxy configure" - gather_facts: true - hosts: - - proxy.home.arpa - vars: - network_ipv4_address: "{{ ansible_facts['default_ipv4']['address'] }}" - proxy_type: "caddy" - roles: - - role: "proxy" - - name: "Git configure" gather_facts: true hosts: - git.home.arpa vars: network_ipv4_address: "{{ ansible_facts['default_ipv4']['address'] }}" - cgit_proxy_host: "proxy.home.arpa" roles: - role: "cgit" diff --git a/molecule/git/molecule.yml b/molecule/git/molecule.yml index 335911db..98931d08 100644 --- a/molecule/git/molecule.yml +++ b/molecule/git/molecule.yml @@ -8,17 +8,6 @@ dependency: driver: name: podman platforms: - - name: proxy.home.arpa - image: proxy - dockerfile: Dockerfile.j2 - platform: "linux/amd64" - pre_build_image: false - privileged: true - command: ${MOLECULE_COMMAND:-"/sbin/init"} - tmpfs: - "/tmp": "rw" - "/run": "rw,exec" - cgroupns_mode: host - name: git.home.arpa image: git dockerfile: Dockerfile.j2 diff --git a/roles/cgit/defaults/main.yml b/roles/cgit/defaults/main.yml index 02168d34..078eda16 100644 --- a/roles/cgit/defaults/main.yml +++ b/roles/cgit/defaults/main.yml @@ -6,4 +6,3 @@ cgit_title: "git" cgit_description: "personal git repositories" cgit_clone_prefix: "ssh://{{ cgit_ssh_user }}@{{ cgit_hostname }}" cgit_ssh_user: "git" -cgit_proxy_host: "proxy.home.arpa" diff --git a/roles/cgit/handlers/main.yml b/roles/cgit/handlers/main.yml index 52ffdbee..516733f7 100644 --- a/roles/cgit/handlers/main.yml +++ b/roles/cgit/handlers/main.yml @@ -4,17 +4,3 @@ ansible.builtin.service: name: lighttpd state: restarted - -- name: "Restart caddy" - become: true - delegate_to: "{{ cgit_proxy_host }}" - ansible.builtin.service: - name: caddy - state: restarted - -- name: "Restart nginx" - become: true - delegate_to: "{{ cgit_proxy_host }}" - ansible.builtin.service: - name: nginx - state: restarted diff --git a/roles/cgit/meta/argument_specs.yml b/roles/cgit/meta/argument_specs.yml index 652598de..48676be9 100644 --- a/roles/cgit/meta/argument_specs.yml +++ b/roles/cgit/meta/argument_specs.yml @@ -4,7 +4,7 @@ argument_specs: options: cgit_hostname: type: "str" - description: "Public hostname for cgit (e.g. git.example.com)" + description: "Hostname for cgit (e.g. git.example.com)" default: "git.example.com" cgit_port: type: "int" @@ -30,11 +30,3 @@ argument_specs: type: "str" description: "System user for SSH git push access" default: "git" - cgit_proxy_host: - type: "str" - description: "Inventory hostname of the proxy container to deploy vhost on" - default: "proxy.home.arpa" - cgit_public_hostname: - type: "str" - description: "Optional public hostname for cgit (e.g. git.a14m.dev); enables public vhost block with TLS" - required: false diff --git a/roles/cgit/tasks/main.yml b/roles/cgit/tasks/main.yml index 17a5675b..c5eeea3b 100644 --- a/roles/cgit/tasks/main.yml +++ b/roles/cgit/tasks/main.yml @@ -52,52 +52,6 @@ mode: "0644" notify: "Restart lighttpd" -- name: "Deploy caddy vhost on proxy" - when: hostvars[cgit_proxy_host]['proxy_type'] == "caddy" - delegate_to: "{{ cgit_proxy_host }}" - block: - - name: "Ensure caddy sites directory exists" - become: true - ansible.builtin.file: - path: "/etc/caddy/sites" - state: directory - owner: "root" - group: "caddy" - mode: "0750" - - - name: "Deploy caddy vhost" - become: true - ansible.builtin.template: - src: "cgit.caddy.j2" - dest: "/etc/caddy/sites/{{ cgit_hostname }}.caddy" - owner: "root" - group: "caddy" - mode: "0640" - notify: "Restart caddy" - -- name: "Deploy nginx vhost on proxy" - when: hostvars[cgit_proxy_host]['proxy_type'] == "nginx" - delegate_to: "{{ cgit_proxy_host }}" - block: - - name: "Ensure nginx vhosts directory exists" - become: true - ansible.builtin.file: - path: "/etc/nginx/vhosts.d" - state: directory - owner: "root" - group: "root" - mode: "0755" - - - name: "Deploy nginx vhost" - become: true - ansible.builtin.template: - src: "cgit.nginx.conf.j2" - dest: "/etc/nginx/vhosts.d/{{ cgit_hostname }}.conf" - owner: "root" - group: "root" - mode: "0644" - notify: "Restart nginx" - - name: "Enable and start services" become: true ansible.builtin.service: diff --git a/roles/cgit/templates/cgit.caddy.j2 b/roles/cgit/templates/cgit.caddy.j2 deleted file mode 100644 index c0a87a18..00000000 --- a/roles/cgit/templates/cgit.caddy.j2 +++ /dev/null @@ -1,5 +0,0 @@ -{% if cgit_public_hostname is defined %} -{{ cgit_public_hostname }} { - reverse_proxy {{ network_ipv4_address }}:{{ cgit_port }} -} -{% endif %} diff --git a/roles/cgit/templates/cgit.nginx.conf.j2 b/roles/cgit/templates/cgit.nginx.conf.j2 deleted file mode 100644 index 4ac0ae43..00000000 --- a/roles/cgit/templates/cgit.nginx.conf.j2 +++ /dev/null @@ -1,28 +0,0 @@ -server { - listen 80; - listen [::]:80; - server_name {{ cgit_hostname }}; - location / { - proxy_pass http://{{ network_ipv4_address }}:{{ cgit_port }}; - } -} -{% if cgit_public_hostname is defined %} - -server { - listen 80; - listen [::]:80; - server_name {{ cgit_public_hostname }}; - return 301 https://$server_name$request_uri; -} - -server { - listen 443 ssl http2; - listen [::]:443 ssl http2; - server_name {{ cgit_public_hostname }}; - ssl_certificate {{ nginx_ssl_certificate }}; - ssl_certificate_key {{ nginx_ssl_certificate_key }}; - location / { - proxy_pass http://{{ network_ipv4_address }}:{{ cgit_port }}; - } -} -{% endif %} diff --git a/roles/proxy/defaults/main.yml b/roles/proxy/defaults/main.yml deleted file mode 100644 index 5f0d40a0..00000000 --- a/roles/proxy/defaults/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -proxy_type: "nginx" diff --git a/roles/proxy/meta/argument_specs.yml b/roles/proxy/meta/argument_specs.yml deleted file mode 100644 index ee11aa1a..00000000 --- a/roles/proxy/meta/argument_specs.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -argument_specs: - main: - options: - proxy_type: - type: "str" - description: "Reverse proxy to use: 'nginx' or 'caddy'" - default: "nginx" diff --git a/roles/proxy/meta/main.yml b/roles/proxy/meta/main.yml deleted file mode 100644 index 5cc03ec2..00000000 --- a/roles/proxy/meta/main.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -dependencies: [] -galaxy_info: - author: "a14m" - description: "Conditionally configure nginx or caddy reverse proxy based on proxy_type" - license: "MIT" - min_ansible_version: "2.18" - platforms: - - name: "ArchLinux" - versions: - - "all" - - name: "Ubuntu" - versions: - - "noble" - - name: "Debian" - versions: - - "bookworm" - - name: "Alpine" - versions: - - "all" diff --git a/roles/proxy/tasks/main.yml b/roles/proxy/tasks/main.yml deleted file mode 100644 index c5626725..00000000 --- a/roles/proxy/tasks/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- name: "Setup proxy" - ansible.builtin.include_role: - name: "{{ proxy_type }}" diff --git a/service.yml b/service.yml index 18a89540..c35aab6a 100644 --- a/service.yml +++ b/service.yml @@ -4,7 +4,7 @@ hosts: - proxy.home.arpa roles: - - role: "proxy" + - role: "caddy" - name: "Git configure" gather_facts: true -- cgit v1.2.3