diff --git a/defaults/main.yml b/defaults/main.yml index 4973996..e1491dd 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -17,6 +17,11 @@ # along with ARA. If not, see . ara: + params: + # If ARA should be installed inside a virtualenv + virtualenv: true + # Location where the virtualenv should be installed + virtualenv_path: /opt/ara-venv config: database: "sqlite:////var/lib/ara/ansible.sqlite" # Host to listen on for embedded server, apache or nginx diff --git a/tasks/apache/mod_wsgi.yml b/tasks/apache/mod_wsgi.yml index 306a341..7026892 100644 --- a/tasks/apache/mod_wsgi.yml +++ b/tasks/apache/mod_wsgi.yml @@ -31,6 +31,8 @@ - name: Get the location of the WSGI script command: which ara-wsgi + environment: + PATH: "{{ path_with_virtualenv | default(omit) }}" register: wsgi_location changed_when: false diff --git a/tasks/embedded/standalone.yml b/tasks/embedded/standalone.yml index ccfe4df..c3a7168 100644 --- a/tasks/embedded/standalone.yml +++ b/tasks/embedded/standalone.yml @@ -18,6 +18,8 @@ - name: Get the location of ara-manage command: which ara-manage + environment: + PATH: "{{ path_with_virtualenv | default(omit) }}" register: ara_manage changed_when: false diff --git a/tasks/main.yml b/tasks/main.yml index a7f089e..02023dd 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -41,11 +41,26 @@ name: pip state: present +# Need to make sure setuptools is up to date +- name: Initialize virtualenv with up-to-date setuptools + become: true + pip: + name: setuptools + state: latest + virtualenv: "{{ ara.params.virtualenv_path }}" + when: ara.params.virtualenv | bool + - name: Install ARA with pip become: true pip: name: ara state: present + virtualenv: "{{ ara.params.virtualenv | bool | ternary(ara.params.virtualenv_path, omit) }}" + +- name: Suffix the virtualenv bin directory to PATH + set_fact: + path_with_virtualenv: "{{ ara.params.virtualenv_path }}/bin:{{ ansible_env.PATH }}" + when: ara.params.virtualenv | bool - name: Create user for ARA become: true @@ -93,8 +108,10 @@ - restart ara - restart nginx -- name: Get ARA installed location - shell: python -c "import os,ara; print(os.path.dirname(ara.__file__))" +- name: Get ARA's installed location + command: python -m ara.setup.path + environment: + PATH: "{{ path_with_virtualenv | default(omit) }}" register: ara_location changed_when: false diff --git a/templates/apache_mod_wsgi.conf.j2 b/templates/apache_mod_wsgi.conf.j2 index e362a55..5083f52 100644 --- a/templates/apache_mod_wsgi.conf.j2 +++ b/templates/apache_mod_wsgi.conf.j2 @@ -5,17 +5,23 @@ LogLevel warn CustomLog {{ apache_log_path }}/ara-access.log combined + SetEnv ANSIBLE_CONFIG /etc/ara/ara.cfg + {% if ara.params.virtualenv -%} + SetEnv ARA_WSGI_USE_VIRTUALENV 1 + SetEnv ARA_WSGI_VIRTUALENV_PATH {{ ara.params.virtualenv_path }} + + WSGIDaemonProcess ara user=ara group=ara processes=1 threads=4 python-home={{ ara.params.virtualenv_path }} + {% else -%} + WSGIDaemonProcess ara user=ara group=ara processes=1 threads=4 + {% endif -%} + WSGIScriptAlias {{ ara.config.application_root }} {{ wsgi_script }} + WSGIProcessGroup ara + WSGIApplicationGroup %{GLOBAL} + Allow from all Satisfy Any - - WSGIDaemonProcess ara user=ara group=ara processes=1 threads=4 - WSGIScriptAlias {{ ara.config.application_root }} {{ wsgi_script }} - WSGIProcessGroup ara - WSGIApplicationGroup %{GLOBAL} - - SetEnv ANSIBLE_CONFIG /etc/ara/ara.cfg diff --git a/vars/Debian.yml b/vars/Debian.yml index feef8c0..7066b81 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -24,6 +24,7 @@ required_packages: - libxslt-dev - python-dev - python-setuptools + - python-virtualenv - debianutils required_wsgi_packages: diff --git a/vars/RedHat.yml b/vars/RedHat.yml index 36c95d7..52f4302 100644 --- a/vars/RedHat.yml +++ b/vars/RedHat.yml @@ -25,6 +25,7 @@ required_packages: - openssl-devel - python-devel - python-setuptools + - python-virtualenv - redhat-rpm-config - which