---
# choose python version and setup a service virtualenv

- include: 22-python2.yml
  when: not use_python3

- include: 23-python3.yml
  when: use_python3

- name: configure virtualenv home directory
  become_user: 'root'
  lineinfile: >
    dest=/etc/environment
    regexp=^WORKON_HOME={{ venvs_path }}
    line=WORKON_HOME={{ venvs_path }}
    state=present

- name: update virtualenv home directory owner
  become_user: 'root'
  file: >
    path={{ venvs_path }}
    owner={{ service_user }}
    group={{ service_group }}
    recurse=yes

- name: enable virtualenv on login
  lineinfile: >
    dest="~{{ service_user }}/.bashrc"
    line="source {{ virtualenv_path }}/bin/activate"
    state=present

- name: go to {{ source_path }} after login
  lineinfile: >
    dest="~{{ service_user }}/.bashrc"
    line="cd {{ source_path }}"
    state=present

---
# choose python version and setup a service virtualenv

- include: 22-python2.yml
  when: not use_python3

- include: 23-python3.yml
  when: use_python3

- name: update virtualenvwrapper and pip
  pip: >
    virtualenv="{{ virtualenv_path }}"
    executable="{{ virtualenv_path }}/bin/pip"
    name={{ item }}
    state=latest
  with_items:
    - "pip==8.1.0"
    - "virtualenvwrapper"

- name: configure virtualenv home directory
  become_user: 'root'
  lineinfile: >
    dest=/etc/environment
    regexp=^WORKON_HOME={{ venvs_path }}
    line=WORKON_HOME={{ venvs_path }}
    state=present

- name: update virtualenv home directory owner
  become_user: 'root'
  file: >
    path={{ venvs_path }}
    owner={{ service_user }}
    group={{ service_group }}
    recurse=yes

- name: enable virtualenv on login
  lineinfile: >
    dest="~{{ service_user }}/.bashrc"
    line="source {{ virtualenv_path }}/bin/activate"
    state=present

- name: go to {{ source_path }} after login
  lineinfile: >
    dest="~{{ service_user }}/.bashrc"
    line="cd {{ source_path }}"
    state=present

Update pip and install virtualenvwrapper by default
Update pip and install virtualenvwrapper by default
