|
@@ -93,108 +93,125 @@
|
|
|
# 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"
|
|
|
state: directory
|
|
|
owner: "{{ admin }}"
|
|
|
group: "{{ user }}"
|
|
|
mode: 02750
|
|
|
|
|
|
# setuptools is excluded on Stretch, because it would pull-in the
|
|
|
# pkg-resources package that then messes with pip freeze etc.
|
|
|
- name: Create Python virtual environment
|
|
|
command: '/usr/bin/virtualenv --python "{{ python_interpreter }}" --prompt "({{ fqdn }})" "{{ home }}/virtualenv"'
|
|
|
command: '/usr/bin/virtualenv {{ no_setuptools }} --python "{{ python_interpreter }}" --prompt "({{ fqdn }})" "{{ home }}/virtualenv"'
|
|
|
args:
|
|
|
creates: "{{ home }}/virtualenv/bin/{{ python_interpreter | basename }}"
|
|
|
become: true
|
|
|
become_user: "{{ admin }}"
|
|
|
tags:
|
|
|
# [ANSIBLE0012] Commands should not change things if nothing needs doing
|
|
|
# This task will not fire if the virtual environment has already bene
|
|
|
# created (thanks to 'creates' parameter).
|
|
|
- skip_ansible_lint
|
|
|
|
|
|
- name: Install latest pip in virtual environment
|
|
|
- name: Install latest pip and setuptools in virtual environment
|
|
|
pip:
|
|
|
name:
|
|
|
- "pip>=18.0.0,<19.0.0"
|
|
|
- "setuptools>=40.0.0,<41.0.0"
|
|
|
virtualenv: "{{ home }}/virtualenv"
|
|
|
become: true
|
|
|
become_user: "{{ admin }}"
|
|
|
|
|
|
# Workaround for:
|
|
|
#
|
|
|
# - https://github.com/pypa/pip/issues/4022
|
|
|
# - https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
|
|
|
# - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=871790
|
|
|
- name: Remove the pkg-resources package from virtual environment (see comments above for details)
|
|
|
pip:
|
|
|
name: pkg-resources
|
|
|
virtualenv: "{{ home }}/virtualenv"
|
|
|
state: absent
|
|
|
become: true
|
|
|
become_user: "{{ admin }}"
|
|
|
|
|
|
- name: Configure project directory for the Python virtual environment
|
|
|
template:
|
|
|
src: "venv_project.j2"
|
|
|
dest: "{{ home }}/virtualenv/.project"
|
|
|
owner: "{{ admin }}"
|
|
|
group: "{{ user }}"
|
|
|
mode: 0640
|
|
|
|
|
|
- name: Deploy virtualenv wrapper
|
|
|
template:
|
|
|
src: "venv_exec.j2"
|
|
|
dest: "{{ home }}/virtualenv/bin/exec"
|
|
|
owner: "{{ admin }}"
|
|
|
group: "{{ user }}"
|
|
|
mode: 0750
|
|
|
|
|
|
- name: Install WSGI server
|
|
|
become: true
|
|
|
become_user: "{{ admin }}"
|
|
|
pip:
|
|
|
name: "{{ item.package }}"
|
|
|
version: "{{ item.version }}"
|
|
|
state: present
|
|
|
virtualenv: "{{ home }}/virtualenv"
|
|
|
with_items:
|
|
|
- package: gunicorn
|
|
|
version: "{{ gunicorn_version }}"
|
|
|
when: "not wsgi_requirements"
|
|
|
register: install_wsgi_server
|
|
|
notify:
|
|
|
- Restart WSGI services
|
|
|
|
|
|
- name: Install futures Python 2 backport (for WSGI server)
|
|
|
become: true
|
|
|
become_user: "{{ admin }}"
|
|
|
pip:
|
|
|
name: "{{ item.package }}"
|
|
|
version: "{{ item.version }}"
|
|
|
state: present
|
|
|
virtualenv: "{{ home }}/virtualenv"
|
|
|
with_items:
|
|
|
- package: futures
|
|
|
version: "{{ futures_version }}"
|
|
|
when: "not wsgi_requirements"
|
|
|
register: install_wsgi_server
|
|
|
notify:
|
|
|
- Restart WSGI services
|
|
|
|
|
|
- include: requirements.yml
|
|
|
when: "wsgi_requirements"
|
|
|
|
|
|
- name: Install additional packages in Python virtual environment
|
|
|
become: true
|
|
|
become_user: "{{ admin }}"
|
|
|
pip:
|
|
|
name: "{{ virtualenv_packages }}"
|
|
|
state: present
|
|
|
virtualenv: "{{ home }}/virtualenv"
|
|
|
register: install_additional_packages_in_virtualenv
|
|
|
when: "virtualenv_packages"
|
|
|
notify:
|
|
|
- Restart WSGI services
|
|
|
|
|
|
- name: Deploy systemd socket configuration for website
|
|
|
template:
|