From c87c59a768f056d74313f0f6ae951d5025e0b303 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Sun, 11 Dec 2016 21:11:55 +0200
Subject: [PATCH] - Install Python packages in a virtualenv.

---
 tasks/main.yml        | 16 ++++++++++++++--
 templates/receiver.sh |  4 +++-
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/tasks/main.yml b/tasks/main.yml
index 8937bd7..2fd346d 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -9,19 +9,31 @@
         - pelican_gitreceive_output is defined
 
 - name: APT install prerequisites
+  when: ansible_pkg_mgr == 'apt'
   apt:
-      name: python-dev
+      name: [python-dev, libssl-dev, libffi-dev, build-essential]
       state: present
       update_cache: yes
       cache_valid_time: 3600
 
+- name: Create virtualenv directory
+  file:
+      path: /var/lib/pelican-gitreceive
+      owner: git
+      group: git
+      mode: 0o0700
+      state: directory
+
 - name: pip install
+  become: True
+  become_user: git
   with_items:
       - pelican
-      - fabric
+      - Fabric
   pip:
       name: '{{ item }}'
       state: present
+      virtualenv: /var/lib/pelican-gitreceive
 
 - name: Create directory structure
   file:
diff --git a/templates/receiver.sh b/templates/receiver.sh
index a7e9e8f..961a809 100644
--- a/templates/receiver.sh
+++ b/templates/receiver.sh
@@ -4,8 +4,10 @@ echo Recieving blog...
 tempdir="$(mktemp -d)"
 cd $tempdir
 tar -xf -
-echo Fetching Git submodules
+echo Fetching Git submodules...
 git submodule update --init --recursive
+echo Activating virtualenv...
+. /var/lib/pelican-gitreceive/bin/activate
 echo Building blog...
 fab  build
 echo Syncing blog...
-- 
GitLab