From 393b87729899649bbea4cab335868a37b2e337b0 Mon Sep 17 00:00:00 2001 From: Lazlo Westerhof Date: Thu, 28 Nov 2024 14:57:08 +0100 Subject: [PATCH] Fix Python virtualenvs --- roles/python3/tasks/install-debian.yml | 1 - roles/yoda_external_user_service/tasks/main.yml | 16 ++++++++++++---- roles/yoda_external_user_service/vars/Debian.yml | 2 +- roles/yoda_moai/tasks/main.yml | 15 ++++++++++++--- roles/yoda_moai/templates/moai.wsgi.j2 | 4 ---- roles/yoda_moai/vars/Debian.yml | 2 +- roles/yoda_web_mock/tasks/main.yml | 15 ++++++++++++--- roles/yoda_web_mock/vars/Debian.yml | 2 +- 8 files changed, 39 insertions(+), 18 deletions(-) diff --git a/roles/python3/tasks/install-debian.yml b/roles/python3/tasks/install-debian.yml index b28c3a932..260e4cdad 100644 --- a/roles/python3/tasks/install-debian.yml +++ b/roles/python3/tasks/install-debian.yml @@ -9,6 +9,5 @@ - python3-dev - python3-pip - python3-venv - - python3-virtualenv - python3-wheel state: present diff --git a/roles/yoda_external_user_service/tasks/main.yml b/roles/yoda_external_user_service/tasks/main.yml index bf6ac7572..775bb66cf 100644 --- a/roles/yoda_external_user_service/tasks/main.yml +++ b/roles/yoda_external_user_service/tasks/main.yml @@ -197,22 +197,30 @@ notify: Restart Apache webserver -- name: Ensure Yoda EUS virtualenv exists +- name: Ensure Yoda EUS venv exists become_user: '{{ yoda_deployment_user }}' become: true ansible.builtin.command: "{{ yoda_external_user_service_python3_path }} -m venv /var/www/extuser/yoda-external-user-service/venv" args: - creates: "/var/www/extuser/yoda-external-user-service/venv" + creates: "/var/www/extuser/yoda-external-user-service/venv/bin/activate_this.py" -- name: Upgrade pip in EUS virtual environment +- name: Upgrade pip and virtualenv in Yoda EUS virtual environment become_user: '{{ yoda_deployment_user }}' become: true ansible.builtin.pip: name: - pip==24.3.1 + - virtualenv==20.28.0 executable: /var/www/extuser/yoda-external-user-service/venv/bin/pip3 - when: not ansible_check_mode + + +- name: Ensure Yoda EUS virtualenv exists + become_user: '{{ yoda_deployment_user }}' + become: true + ansible.builtin.command: "/var/www/extuser/yoda-external-user-service/venv/bin/python3 -m virtualenv /var/www/extuser/yoda-external-user-service/venv" + args: + creates: "/var/www/extuser/yoda-external-user-service/venv/bin/activate_this.py" # Change detection in git repositories is unreliable in some Ansible versions, so we always diff --git a/roles/yoda_external_user_service/vars/Debian.yml b/roles/yoda_external_user_service/vars/Debian.yml index 32eef90d2..b95d08920 100644 --- a/roles/yoda_external_user_service/vars/Debian.yml +++ b/roles/yoda_external_user_service/vars/Debian.yml @@ -5,7 +5,7 @@ openssl_private_dir: '/etc/ssl/private/' openssl_certs_dir: '/etc/ssl/certs' yoda_external_user_service_python3_path: /usr/bin/python3 -yoda_external_user_service_python3_include_path: /usr/include/python3.8 +yoda_external_user_service_python3_include_path: /usr/include/python3.12 yoda_external_user_service_site_config_dir: /etc/apache2/sites-available yoda_external_user_service_site_enabled_config_dir: /etc/apache2/sites-enabled yoda_external_user_service_site_config_file: 003-yoda-eus-vhost.conf diff --git a/roles/yoda_moai/tasks/main.yml b/roles/yoda_moai/tasks/main.yml index 43b4fa211..bd7264c68 100644 --- a/roles/yoda_moai/tasks/main.yml +++ b/roles/yoda_moai/tasks/main.yml @@ -47,23 +47,32 @@ register: repochanges -- name: Ensure Yoda MOAI virtualenv exists +- name: Ensure Yoda MOAI venv exists become_user: '{{ yoda_moai_user }}' become: true ansible.builtin.command: "{{ yoda_moai_python3_path }} -m venv {{ yoda_moai_home }}/yoda-moai/venv" args: - creates: "{{ yoda_moai_home }}/yoda-moai/venv" + creates: "{{ yoda_moai_home }}/yoda-moai/venv/bin/activate_this.py" -- name: Upgrade pip in virtual environment +- name: Upgrade pip and virtualenv in Yoda MOAI environment become_user: '{{ yoda_moai_user }}' become: true ansible.builtin.pip: name: - pip==24.3.1 + - virtualenv==20.28.0 executable: /var/www/moai/yoda-moai/venv/bin/pip3 +- name: Ensure Yoda MOAI virtualenv exists + become_user: '{{ yoda_moai_user }}' + become: true + ansible.builtin.command: "{{ yoda_moai_home }}/yoda-moai/venv/bin/python3 -m virtualenv {{ yoda_moai_home }}/yoda-moai/venv" + args: + creates: "{{ yoda_moai_home }}/yoda-moai/venv/bin/activate_this.py" + + # We use the PySqlite3 dialect to avoid compatibility issues between SQLAlchemy # and the old SQlite version bundled with CentOS 7 - name: Ensure PySQLite3 is installed in MOAI virtual environment diff --git a/roles/yoda_moai/templates/moai.wsgi.j2 b/roles/yoda_moai/templates/moai.wsgi.j2 index d83be1bc7..bd48c2fee 100644 --- a/roles/yoda_moai/templates/moai.wsgi.j2 +++ b/roles/yoda_moai/templates/moai.wsgi.j2 @@ -2,10 +2,6 @@ import configparser import os import sys -activate_this = '/var/www/moai/yoda-moai/venv/bin/activate_this.py' -with open(activate_this) as file_: - exec(file_.read(), dict(__file__=activate_this)) - from paste.deploy import loadapp from logging.config import fileConfig diff --git a/roles/yoda_moai/vars/Debian.yml b/roles/yoda_moai/vars/Debian.yml index 05e25ed03..6a8550972 100644 --- a/roles/yoda_moai/vars/Debian.yml +++ b/roles/yoda_moai/vars/Debian.yml @@ -5,7 +5,7 @@ openssl_private_dir: '/etc/ssl/private/' openssl_certs_dir: '/etc/ssl/certs' yoda_moai_python3_path: /usr/bin/python3 -yoda_moai_python3_include_path: /usr/include/python3.8 +yoda_moai_python3_include_path: /usr/include/python3.12 yoda_moai_sqlite3_include_path: /usr/include yoda_moai_sqlite3_lib_path: /usr/lib/x86_64-linux-gnu diff --git a/roles/yoda_web_mock/tasks/main.yml b/roles/yoda_web_mock/tasks/main.yml index 9c55c9ac5..c4c2b9a71 100644 --- a/roles/yoda_web_mock/tasks/main.yml +++ b/roles/yoda_web_mock/tasks/main.yml @@ -32,24 +32,33 @@ force: true -- name: Ensure Yoda web mock virtualenv exists +- name: Ensure Yoda web mock venv exists become_user: '{{ yoda_deployment_user }}' become: true - ansible.builtin.command: "{{ yoda_web_mock_python3_path }} -m venv /var/www/webmock/venv" + ansible.builtin.command: "python3 -m venv /var/www/webmock/venv" args: creates: "/var/www/webmock/venv" -- name: Upgrade pip in Yoda web mock environment +- name: Upgrade pip and virtualenv in Yoda web mock environment become_user: '{{ yoda_deployment_user }}' become: true ansible.builtin.pip: name: - pip==24.3.1 + - virtualenv==20.28.0 executable: /var/www/webmock/venv/bin/pip3 when: not ansible_check_mode +- name: Ensure Yoda web mock virtualenv exists + become_user: '{{ yoda_deployment_user }}' + become: true + ansible.builtin.command: "{{ yoda_web_mock_python3_path }} -m virtualenv /var/www/webmock/venv" + args: + creates: "/var/www/webmock/venv/bin/activate_this.py" + + # Change detection in git repositories is unreliable in some Ansible versions, so we always # run this task, just to be sure. - name: Ensure Yoda web mock dependencies are installed diff --git a/roles/yoda_web_mock/vars/Debian.yml b/roles/yoda_web_mock/vars/Debian.yml index 00a2c49ba..e2a6625e3 100644 --- a/roles/yoda_web_mock/vars/Debian.yml +++ b/roles/yoda_web_mock/vars/Debian.yml @@ -1,4 +1,4 @@ --- # copyright Utrecht University -yoda_web_mock_python3_path: /usr/bin/python3 +yoda_web_mock_python3_path: /var/www/webmock/venv/bin/python3