|
@@ -81,20 +81,31 @@
|
|
|
notify:
|
|
|
- Restart WSGI services
|
|
|
|
|
|
# Ignore failures - the virtual environment might not have been
|
|
|
# created yet. Don't use --version because Python 2 outputs to stderr,
|
|
|
# and Python 3 outputs to stdout.
|
|
|
- name: Check current version of Python used in virtual environment (if any)
|
|
|
command: "{{ home }}/virtualenv/bin/python -c \"import sys; print(sys.version.split(' ')[0])\""
|
|
|
- name: Retrieve requested Python interpreter version
|
|
|
command:
|
|
|
argv:
|
|
|
- "{{ python_interpreter }}"
|
|
|
- "-c"
|
|
|
- "import sys; print(sys.version.split(' ')[0])"
|
|
|
changed_when: false
|
|
|
register: python_interpreter_version
|
|
|
|
|
|
- name: Retrieve virtual environment Python interpreter version (if initialised)
|
|
|
command:
|
|
|
argv:
|
|
|
- "{{ home }}/virtualenv/bin/python"
|
|
|
- "-c"
|
|
|
- "import sys; print(sys.version.split(' ')[0])"
|
|
|
# Virtual environment perhaps does not exist.
|
|
|
failed_when: false
|
|
|
changed_when: false
|
|
|
register: current_python_version
|
|
|
register: virtualenv_python_version
|
|
|
|
|
|
- name: Remove existing Python virtual environment (wrong Python version)
|
|
|
- name: Remove virtual environment if Python version does not match
|
|
|
file:
|
|
|
path: "{{ home }}/virtualenv"
|
|
|
state: absent
|
|
|
when: "current_python_version.rc == 0 and not current_python_version.stdout.startswith('3')"
|
|
|
when: "virtualenv_python_version.rc != 0 or virtualenv_python_version.stdout.strip() != python_interpreter_version.stdout.strip()"
|
|
|
notify:
|
|
|
- Restart WSGI services
|
|
|
|