Skip to content

Commit

Permalink
add virtualenv role
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Sobolev committed Dec 13, 2014
1 parent 9fe8345 commit a359885
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
19 changes: 19 additions & 0 deletions roles/virtualenv/README.rst
@@ -0,0 +1,19 @@
This roles allows to create a Python virtual environment.

The role should be used with the following parameters:

``venv_user``
The user under which the virtual environment is created

``venv_home_dir``
ansible likes absolute paths in way too many places, the virtual
environment is created in the users' home directory and this is its path

``venv_name``
The name of the virtual environment

``venv_packages``
packages to be installed using 'pkgng'

``venv_python_packages``
Python packages to be installed using 'pip install'
28 changes: 28 additions & 0 deletions roles/virtualenv/tasks/main.yml
@@ -0,0 +1,28 @@
---
# This is mostly for pysqlite that needs to find locally installed sqlite3
# headers and libraries. But it might be needed for other modules as well.
- name: prepare ~/.pydistutils.cfg
ini_file:
dest: "{{ venv_home_dir }}/.pydistutils.cfg"
section: "build_ext"
option: "{{ item.option }}"
value: "{{ item.value }}"
owner: "{{ venv_user }}"
with_items:
- option: include_dirs
value: "/usr/local/include"
- option: library_dirs
value: "/usr/local/lib"

- name: install system packages
pkgng:
name: "{{item}}"
state: present
with_items: venv_packages

- name: create the virtual environment
sudo_user: "{{ venv_user }}"
pip:
name: "{{ item }}"
virtualenv: "{{ venv_home_dir }}/{{ venv_name }}"
with_items: venv_python_packages

0 comments on commit a359885

Please sign in to comment.