diff --git a/tasks/main.yml b/tasks/main.yml
index 8937bd7468235aa2f5299c810eb8b5b6127e36e6..7f49dc840a77b68187ff8da2ca176c74299b272a 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -3,12 +3,13 @@
 - name: Assertions
   assert:
     that:
-        - ansible_os_family in ['OpenBSD', 'Debian']
+        - ansible_os_family in pelican_gitreceive_www_root
         - ansible_distribution_release in ['6.0', 'xenial', 'trusty', 'jessie']
         - pelican_gitreceive_public_keys is iterable
         - pelican_gitreceive_output is defined
 
 - name: APT install prerequisites
+  when: ansible_pkg_mgr == 'apt'
   apt:
       name: python-dev
       state: present
@@ -25,7 +26,7 @@
 
 - name: Create directory structure
   file:
-      path: /var/www/htdocs/www.shore.co.il/blog/
+      path: '{{ pelican_gitreceive_www_root[ansible_os_family] }}/blog/'
       owner: git
       group: git
       state: directory
diff --git a/templates/receiver.sh b/templates/receiver.sh
index a7e9e8fa481958782a90a48d372a5eb3078f6f09..bf8d7771e990796d9e3b901b04f112fceeea0715 100644
--- a/templates/receiver.sh
+++ b/templates/receiver.sh
@@ -1,16 +1,41 @@
 #!/bin/sh
 set -eu
-echo Recieving blog...
-tempdir="$(mktemp -d)"
-cd $tempdir
+
+# This part was copied verbatim from
+# https://github.com/progrium/gitreceive/wiki/TipsAndTricks
+fetch_submodules () {
+    # We reinitialize .git to avoid conflicts
+    rm -fr .git
+    # GIT_DIR is previously set by gitreceive to ".", we want it back to default
+    # for this
+    unset GIT_DIR
+    git init .
+
+    # We read the submodules from .gitmodules
+    git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
+        while read path_key path
+        do
+            rm -fr $path
+            url_key=`echo $path_key | sed 's/\.path/.url/'`
+            url=`git config -f .gitmodules --get "$url_key"`
+            git submodule add $url $path
+        done
+}
+
+mkdir -p /var/tmp/gitreceive
+cd /var/tmp/gitreceive
+echo '----> Unpacking ...'
 tar -xf -
-echo Fetching Git submodules
-git submodule update --init --recursive
-echo Building blog...
+if [ -f .gitmodules ]
+then
+    echo '----> Fetching submodules ...'
+    fetch_submodules
+fi
+echo '----> Building blog ...'
 fab  build
-echo Syncing blog...
+echo '----> Copying blog ...'
 rsync -Prv --delete --cvs-exclude output/ {{ pelican_gitreceive_output }}
-echo Cleanup...
+echo '----> Cleanup ...'
 cd -
-rm -r "$tempdir"
-echo Successfully finished...
+rm -rf /var/tmp/gitreceive
+echo '----> OK.'
diff --git a/tests/playbook.yml b/tests/playbook.yml
index aec7729a9062d855ae3174e807d6152f6c7ebfa3..3b01e04384987d038c5854c63c6079c99d42dfd7 100644
--- a/tests/playbook.yml
+++ b/tests/playbook.yml
@@ -22,3 +22,55 @@
     - role: adarnimrod.nginx
     - role: pelican-gitreceive
       pelican_gitreceive_public_keys: ['{{ lookup("file", "id_rsa.pub") }}']
+  post_tasks:
+      - name: Install curl
+        package:
+            name: curl
+            state: present
+
+      - name: Create .ssh directory
+        file:
+            path: /root/.ssh
+            owner: root
+            group: 0
+            mode: 0o0700
+            state: directory
+
+      - name: Copy private SSH key
+        copy:
+            src: id_rsa
+            dest: /root/.ssh/blog_rsa
+            owner: root
+            group: 0
+            mode: 0o0400
+
+      - name: Add SSH config
+        blockinfile:
+            dest: /root/.ssh/config
+            state: present
+            create: yes
+            block: |
+                Host localhost
+                HostName localhost
+                User git
+                IdentityFile /root/.ssh/blog_rsa
+
+      - name: Clone test blog
+        git:
+            dest: /root/blog
+            repo: https://www.shore.co.il/git/blog
+            version: master
+            recursive: yes
+
+      - name: Add localhost host keys to known hosts
+        shell: ssh-keyscan localhost > /root/.ssh/known_hosts
+        args:
+            creates: /root/.ssh/known_hosts
+
+      - name: Add localhost as a git remote
+        blockinfile:
+            dest: /root/blog/.git/config
+            block: |
+                [remote "test"]
+                    url = git@localhost:test
+                    fetch = +refs/heads/*:refs/remotes/test/*
diff --git a/tests/templates/nginx/sites-enabled/testblog b/tests/templates/nginx/sites-enabled/testblog
new file mode 100644
index 0000000000000000000000000000000000000000..433f3405d5634c97fcc734f515a4802609c7eb04
--- /dev/null
+++ b/tests/templates/nginx/sites-enabled/testblog
@@ -0,0 +1,6 @@
+server {
+    listen 80;
+    listen [::]:80;
+    root {{ pelican_gitreceive_www_root[ansible_os_family] }}/blog;
+    server_name localhost;
+}
diff --git a/tests/test_pelican-gitreceive.py b/tests/test_pelican-gitreceive.py
new file mode 100644
index 0000000000000000000000000000000000000000..196d591d292405e482845f646fa2435ae16809a7
--- /dev/null
+++ b/tests/test_pelican-gitreceive.py
@@ -0,0 +1,25 @@
+from testinfra.utils.ansible_runner import AnsibleRunner
+
+testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')
+
+
+def test_git_push(Command, Sudo):
+    with Sudo():
+        Command('rm -rf /home/git/test /var/tmp/gitreceive')
+        push = Command('git -C /root/blog push test')
+    assert push.rc == 0
+    for message in ['----> Unpacking ...', '----> Fetching submodules ...',
+                    '----> Building blog ...', 'Copying blog ...',
+                    '----> Cleanup ...', '----> OK.']:
+        assert message in push.stderr
+    with Sudo():
+        second_push = Command('git -C /root/blog push test')
+    assert second_push.rc == 0
+    assert 'Everything up-to-date' in second_push.stderr
+
+
+def test_blog_website(Command):
+    curl = Command('curl http://localhost/')
+    assert curl.rc == 0
+    assert '<title>My notes and rumblings</title>' in curl.stdout
+    assert 'Mockingbird theme' in curl.stdout