#####################################
### someone"s ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2026 by someone <someone@somenet.org>
#
---
- name: install gitweb
  apt:
    pkg:
    - fcgiwrap
    - gitweb
    state: present
    policy_rc_d: 101
  tags: "online"


- name: add www-data user to group git
  user:
    name: "www-data"
    groups: "git"
    append: yes
    createhome: no
    state: present


- name: include vars_nginx_vhost_custom
  include_vars:
    file: "{{item}}"
    name: vars_nginx_vhost_custom
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/vars_nginx_vhost_custom.yml"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/vars_nginx_vhost_custom.yml"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/vars_nginx_vhost_custom.yml"
    - "default/vars_nginx_vhost_custom.yml"


- name: configure gitweb vhost
  include_role:
    name: server/nginx/vhost-unified
  vars:
    vhost_name: "git.somenet.org"
    vhost_custom:
      vhost_custom_pre_server: "{{vars_nginx_vhost_custom.vhost_custom_pre_server}}"
      vhost_custom: "{{vars_nginx_vhost_custom.vhost_custom}}"


- name: setup gitweb config dir
  file:
    path: "/etc/gitweb/"
    state: directory
    mode: 0755
    owner: "root"
    group: "root"


- name: copy gitweb_public.cfg
  copy:
    src: "{{item}}"
    dest: "/etc/gitweb/public.conf"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/public.cfg"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/public.cfg"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/public.cfg"
    - "default/public.cfg"


- name: copy public_header.html
  copy:
    src: "{{item}}"
    dest: "/etc/gitweb/public_header.html"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/public_header.html"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/public_header.html"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/public_header.html"
    - "default/public_header.html"


- name: copy public_ht.html
  copy:
    src: "{{item}}"
    dest: "/etc/gitweb/public_ht.html"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/public_ht.html"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/public_ht.html"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/public_ht.html"
    - "default/public_ht.html"
