Skip to content

Instantly share code, notes, and snippets.

@mikefromit
Last active June 28, 2016 15:50
Show Gist options
  • Save mikefromit/4281f29013fe3b4306a87cb64a2ad1fd to your computer and use it in GitHub Desktop.
Save mikefromit/4281f29013fe3b4306a87cb64a2ad1fd to your computer and use it in GitHub Desktop.
A simple ansible example to install virtualenvwrapper and config

config_virtualenvwrapper.yml

---
- 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment