Changeset - 1bf64c5d02ff
[Not reviewed]
0 1 0
Branko Majic (branko) - 6 years ago 2018-07-30 15:03:55
branko@majic.rs
MAR-131: Recreate Python virtualenv in wsgi_website role if Python version differs from requested.
1 file changed with 18 insertions and 1 deletions:
0 comments (0 inline, 0 general)
roles/wsgi_website/tasks/main.yml
Show inline comments
 
@@ -85,6 +85,23 @@
 
    state: link
 
  when: "'libmariadb-client-lgpl-dev-compat' in packages"
 

	
 
# 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])\""
 
  failed_when: false
 
  changed_when: false
 
  register: current_python_version
 

	
 
- name: Remove existing Python virtual environment (wrong Python version)
 
  file:
 
    path: "{{ home }}/virtualenv"
 
    state: absent
 
  when: "current_python_version.rc == 0 and not current_python_version.stdout.startswith(python_version | string)"
 
  notify:
 
    - Restart WSGI services
 

	
 
- name: Create directory for storing the Python virtual environment
 
  file:
 
    path: "{{ home }}/virtualenv"
 
@@ -96,7 +113,7 @@
 
- name: Create Python virtual environment
 
  command: '/usr/bin/virtualenv --python "{{ python_interpreter }}" --prompt "({{ fqdn }})" "{{ home }}/virtualenv"'
 
  args:
 
    creates: "{{ home }}/virtualenv/bin/activate"
 
    creates: "{{ home }}/virtualenv/bin/{{ python_interpreter | basename }}"
 
  become: true
 
  become_user: "{{ admin }}"
 
  tags:
0 comments (0 inline, 0 general)