--- a/playbook-example.yml Tue Jul 17 02:56:41 2018 +0000
+++ b/playbook-example.yml Tue Jul 17 13:17:59 2018 +0800
\ No newline at end of file
+ # NOTE: you probably don't want to run these pre_tasks on a real box. Just
+ # bear in mind that to be able to access hgweb from inside the box, you
+ # need to use the virtual host name (i.e. http://127.0.0.1/ won't work).
+ # So make sure you either have DNS records for hg.mydomain or it's in
+ - name: Update /etc/hosts
+ line: '127.0.0.1 {{ hostname }} hg.{{ hostname }}'
+ # NOTE: hgweb role depends on Lighttpd and uWSGI being installed. It's
+ # recommended to install them in separate lighttpd and uwsgi roles, not in
+ # pre_tasks like in this example playbook.
+ - name: Install Lighttpd
+ # NOTE: hgweb role notifies two handlers:
+ # Naturally, the handlers are not defined in the role itself, so this
+ # example playbook includes them here.
+ - name: restart lighttpd
+# NOTE: how to test that it works correctly (also see the note about DNS):
+# curl -I http://hg.mydomain/
+# curl -I http://hg.mydomain/static/mercurial.js
+# then check /var/log/uwsgi/app/50-hgweb.log for problems
+# make sure it doesn't see requests /static/ (Lighttpd should handle them)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/defaults/main.yml Tue Jul 17 13:17:59 2018 +0800
+hgweb_contact: 'Me Myself <me@mydomain>'
+hgweb_mercurial_url: https://www.mercurial-scm.org/repo/hg
+hgweb_mercurial_rev: stable
+hgweb_evolve_url: https://www.mercurial-scm.org/repo/evolve
+hgweb_evolve_rev: stable
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/files/robots.txt Tue Jul 17 13:17:59 2018 +0800
+Disallow: /*/comparison/
+# Graph page is a more expensive log
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/handlers/main.yml Tue Jul 17 13:17:59 2018 +0800
+ command: make --directory /home/{{ hgweb_user }}/hg/ local
+ become_user: '{{ hgweb_user }}'
+ path: /home/{{ hgweb_user }}/hgwebfiles/hgweb.wsgi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/tasks/appinstall.yml Tue Jul 17 13:17:59 2018 +0800
+- name: Ensure required directories exist
+ path: /home/{{ hgweb_user }}/{{ item }}/
+- name: Pull Mercurial {{ hgweb_mercurial_rev }}
+ repo: '{{ hgweb_mercurial_url }}'
+ dest: /home/{{ hgweb_user }}/hg/
+ revision: '{{ hgweb_mercurial_rev }}'
+- name: Pull Evolve {{ hgweb_evolve_rev }}
+ repo: '{{ hgweb_evolve_url }}'
+ dest: /home/{{ hgweb_user }}/evolve/
+ revision: '{{ hgweb_evolve_rev }}'
+- name: Add config files
+ dest: /home/{{ hgweb_user }}/hgwebfiles/{{ item }}
+ dest: /home/{{ hgweb_user }}/hgwebfiles/robots.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/tasks/main.yml Tue Jul 17 13:17:59 2018 +0800
+ name: '{{ hgweb_user }}'
+- name: Install packages
+ - python-pygments # for hightlight extension
+ tags: [packages, inert]
+- include: appinstall.yml
+ become_user: '{{ hgweb_user }}'
+ src: etc/uwsgi/apps-available/hgweb.yaml
+ dest: /etc/uwsgi/apps-available/hgweb.yaml
+- name: Enable uWSGI app
+ src: /etc/uwsgi/apps-available/hgweb.yaml
+ dest: /etc/uwsgi/apps-enabled/50-hgweb.yaml
+- name: Add {{ hgweb_subdomain }}.{{ hostname }} Lighttpd site
+ src: etc/lighttpd/conf-available/hgweb.conf
+ dest: /etc/lighttpd/conf-available/{{ hgweb_subdomain }}.{{ hostname }}.conf
+- name: Enable {{ hgweb_subdomain }}.{{ hostname }} Lighttpd site
+ src: /etc/lighttpd/conf-available/{{ hgweb_subdomain }}.{{ hostname }}.conf
+ dest: /etc/lighttpd/conf-enabled/50-{{ hgweb_subdomain }}.{{ hostname }}.conf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/templates/etc/lighttpd/conf-available/hgweb.conf Tue Jul 17 13:17:59 2018 +0800
+$HTTP["host"] == "{{ hgweb_subdomain }}.{{ hostname }}" {
+ server.document-root = "/home/{{ hgweb_user }}/hg/mercurial/templates/"
+ $HTTP["url"] !~ "^/static/|^/robots.txt$" {
+ # mod_proxy uses "host" instead of "socket", because of course
+ proxy.server = ( "" => (( "host" => "/home/{{ hgweb_user }}/hgwebfiles/socket" )) )
+ "/robots.txt" => "/home/{{ hgweb_user }}/hgwebfiles/robots.txt"
+ url.redirect-code = 301
+ "/favicon.ico" => "/static/hgicon.png"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/templates/etc/uwsgi/apps-available/hgweb.yaml Tue Jul 17 13:17:59 2018 +0800
+ chdir: /home/{{ hgweb_user }}/hgwebfiles/
+ touch-reload: hgweb.wsgi
+ # PATH_INFO is empty when using uwsgi protocol?
+ processes: {{ hgweb_workers }}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/templates/hgweb.conf Tue Jul 17 13:17:59 2018 +0800
+/ = /home/{{ hgweb_user }}/repos/*
+evolve.serveronly = /home/{{ hgweb_user }}/evolve/hgext3rd/evolve/serveronly.py
+baseurl = http://{{ hgweb_subdomain }}.{{ hostname }}/
+logourl = http://{{ hgweb_subdomain }}.{{ hostname }}/
+contact = {{ hgweb_contact }}
+highlightfiles = size('<100k')
+highlightonlymatchfilename = True
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/hgweb/templates/hgweb.wsgi Tue Jul 17 13:17:59 2018 +0800
+# Path to repo or hgweb config to serve (see 'hg help hgweb')
+config = "/home/{{ hgweb_user }}/hgwebfiles/hgweb.conf"
+# Uncomment and adjust if Mercurial is not installed system-wide
+# (consult "installed modules" path from 'hg debuginstall'):
+import sys; sys.path.insert(0, "/home/{{ hgweb_user }}/hg/")
+# Uncomment to send python tracebacks to the browser if an error occurs:
+#import cgitb; cgitb.enable()
+# enable demandloading to reduce startup time
+from mercurial import demandimport; demandimport.enable()
+from mercurial.hgweb import hgweb
+application = hgweb(config)