---
- name: virtualenv setup
hosts: localhost
vars:
venv_dir: ~/.environments
tasks:
- name: run apt-get update
sudo: yes
apt: update_cache=yes
when: ansible_distribution == 'Ubuntu'
- name: install python setup-tools on Ubuntu
sudo: yes
apt: name=python-setuptools
when: ansible_distribution == 'Ubuntu'
- name: install pip
easy_install: name=pip
# Install virtualenv, and virtualenvwrapper
- name: install virtualenvwrapper
sudo: yes
pip: name=virtualenvwrapper
# Configure virtualenvwrapper
- name: update bashrc for virtualenvwrapper
lineinfile:
dest=~/.bash_profile
create=True
insertafter=EOF
regexp="{{ item.regexp }}"
line="{{ item.line }}"
with_items:
- { line: 'export WORKON_HOME=$HOME/.environments', regexp: '^export WORKON_HOME' }
- { line: 'export PIP_VIRTUALENV_BASE=$WORKON_HOME', regexp: '^export PIP_VIRTUALENV_BASE='}
- { line: 'export PIP_RESPECT_VIRTUALENV=true', regexp: '^export PIP_RESPECT_VIRTUALENV=true'}
- { line: 'source /usr/local/bin/virtualenvwrapper.sh', regexp: '^source /usr/local/bin/virtualenvwrapper.sh'}
Run the playbook:
ansible-playbook config_virtualenvwrapper.yml -i "localhost" --ask-sudo-pass