From 3bb147b5be91621dd83469d7d4a460357cc69be5 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Sun, 12 May 2024 10:13:46 +0200 Subject: [PATCH 1/4] feat(defaults): split into several files --- defaults/main/base.yml | 27 +++++++++++++ defaults/{main.yml => main/python.yml} | 56 ++------------------------ defaults/main/venv.yml | 39 ++++++++++++++++++ 3 files changed, 69 insertions(+), 53 deletions(-) create mode 100644 defaults/main/base.yml rename defaults/{main.yml => main/python.yml} (83%) create mode 100644 defaults/main/venv.yml diff --git a/defaults/main/base.yml b/defaults/main/base.yml new file mode 100644 index 0000000..3788b64 --- /dev/null +++ b/defaults/main/base.yml @@ -0,0 +1,27 @@ +--- +## +# role main options +## + +python_24: false +python_26: false +python_27: false +python_31: false +python_32: false +python_33: false +python_34: false +python_35: false +python_36: false +python_37: false +python_38: false +python_39: false +python_310: false +python_311: false +python_312: true +python_313: false + +pillow: false +lxml: false + +# fine grained settings +base_install_folder: "/srv" diff --git a/defaults/main.yml b/defaults/main/python.yml similarity index 83% rename from defaults/main.yml rename to defaults/main/python.yml index a01f051..71f9059 100644 --- a/defaults/main.yml +++ b/defaults/main/python.yml @@ -1,27 +1,9 @@ --- ## -# role main options +# Pythons configuration ## -python_24: false -python_26: false -python_27: false -python_31: false -python_32: false -python_33: false -python_34: false -python_35: false -python_36: false -python_37: false -python_38: false -python_39: false -python_310: false -python_311: false -python_312: true -python_313: false - -pillow: false -lxml: false +ftp_url: "https://www.python.org/ftp/python" versions: py24: "2.4.6" @@ -59,41 +41,9 @@ hashes: py312: "8defb33f0c37aa4bdd3a38ba52abde4e" py313: "e1208b22c67c77de72a5e20025b2fb53" -venv_versions: - py24: "1.7.2" - py26: "1.10" - py27: "16.6.1" - ## -# fine grained settings +# Specific python version details, based on the variables above ## -base_install_folder: "/srv" -ftp_url: "https://www.python.org/ftp/python" -pkg_url: "https://files.pythonhosted.org/packages" - -venv24: - version: "{{ venv_versions.py24 }}" - file_hash: "7b88d35d0a353ec70e42aa37fd8b0bd1c643419c80f022ffaafa4d6449f0" - url: "{{ pkg_url }}/16/86/{{ file_hash }}/virtualenv-1.7.2.tar.gz" - md5: "b5d63b05373a4344ae099a68875aae78" - tar_file: "/tmp/virtualenv-{{ venv_versions.py24 }}.tar.gz" - sources: "/tmp/virtualenv-{{ venv_versions.py24 }}" - -venv26: - version: "{{ venv_versions.py26 }}" - file_hash: "f425e456e017af4801bb08920e30c149a44ac0c194f2225bdb712e77701c" - url: "{{ pkg_url }}/d5/5b/{{ file_hash }}/virtualenv-1.10.tar.gz" - md5: "9745c28256c70c76d36adb3767a00212" - tar_file: "/tmp/virtualenv-{{ venv_versions.py26 }}.tar.gz" - sources: "/tmp/virtualenv-{{ venv_versions.py26 }}" - -venv27: - version: "{{ venv_versions.py27 }}" - file_hash: "706af3ee62032933a3217454609c50a5325a6bd9c2c2f495b58c456ba286" - url: "{{ pkg_url }}/37/27/{{ file_hash }}/virtualenv-16.6.1.tar.gz" - md5: "b05b03dc6ecb3caaa3d58bfcccf4e786" - tar_file: "/tmp/virtualenv-{{ venv_versions.py27 }}.tar.gz" - sources: "/tmp/virtualenv-{{ venv_versions.py27 }}" py24: version: "{{ versions.py24 }}" diff --git a/defaults/main/venv.yml b/defaults/main/venv.yml new file mode 100644 index 0000000..b6bc8a4 --- /dev/null +++ b/defaults/main/venv.yml @@ -0,0 +1,39 @@ +--- +## +# Virtual environment related configuration +## + +pkg_url: "https://files.pythonhosted.org/packages" + +venv_versions: + py24: "1.7.2" + py26: "1.10" + py27: "16.6.1" + +## +# main venvs configuration, based on the variables above +## + +venv24: + version: "{{ venv_versions.py24 }}" + file_hash: "7b88d35d0a353ec70e42aa37fd8b0bd1c643419c80f022ffaafa4d6449f0" + url: "{{ pkg_url }}/16/86/{{ file_hash }}/virtualenv-1.7.2.tar.gz" + md5: "b5d63b05373a4344ae099a68875aae78" + tar_file: "/tmp/virtualenv-{{ venv_versions.py24 }}.tar.gz" + sources: "/tmp/virtualenv-{{ venv_versions.py24 }}" + +venv26: + version: "{{ venv_versions.py26 }}" + file_hash: "f425e456e017af4801bb08920e30c149a44ac0c194f2225bdb712e77701c" + url: "{{ pkg_url }}/d5/5b/{{ file_hash }}/virtualenv-1.10.tar.gz" + md5: "9745c28256c70c76d36adb3767a00212" + tar_file: "/tmp/virtualenv-{{ venv_versions.py26 }}.tar.gz" + sources: "/tmp/virtualenv-{{ venv_versions.py26 }}" + +venv27: + version: "{{ venv_versions.py27 }}" + file_hash: "706af3ee62032933a3217454609c50a5325a6bd9c2c2f495b58c456ba286" + url: "{{ pkg_url }}/37/27/{{ file_hash }}/virtualenv-16.6.1.tar.gz" + md5: "b05b03dc6ecb3caaa3d58bfcccf4e786" + tar_file: "/tmp/virtualenv-{{ venv_versions.py27 }}.tar.gz" + sources: "/tmp/virtualenv-{{ venv_versions.py27 }}" From 8b26566c4caeacdf8f301e33678611b95e7fdfa6 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Sun, 12 May 2024 10:16:08 +0200 Subject: [PATCH 2/4] fix(defaults): use more variables --- defaults/main/venv.yml | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/defaults/main/venv.yml b/defaults/main/venv.yml index b6bc8a4..a7dd60f 100644 --- a/defaults/main/venv.yml +++ b/defaults/main/venv.yml @@ -1,6 +1,8 @@ --- ## # Virtual environment related configuration +# +# !! Note that Python 2.7 is installed slightly different ## pkg_url: "https://files.pythonhosted.org/packages" @@ -8,7 +10,19 @@ pkg_url: "https://files.pythonhosted.org/packages" venv_versions: py24: "1.7.2" py26: "1.10" - py27: "16.6.1" + py27: "20.15.1" + +venv_url_hashes: + py24: "7b88d35d0a353ec70e42aa37fd8b0bd1c643419c80f022ffaafa4d6449f0" + py26: "f425e456e017af4801bb08920e30c149a44ac0c194f2225bdb712e77701c" + py27: "df7c7b1b7a5ac4e41fac24c3682c1cc32f2c1d683d308bba2500338d1e3e" + +venv_file_hashes: + py24: "b5d63b05373a4344ae099a68875aae78" + py26: "9745c28256c70c76d36adb3767a00212" + py27: "e9a76a95dc28cf9b55cfc87bd4eef20c" + +venv27_wheel_name: "virtualenv-{{ venv_versions.py27 }}-py2.py3-none-any.whl" ## # main venvs configuration, based on the variables above @@ -16,24 +30,20 @@ venv_versions: venv24: version: "{{ venv_versions.py24 }}" - file_hash: "7b88d35d0a353ec70e42aa37fd8b0bd1c643419c80f022ffaafa4d6449f0" - url: "{{ pkg_url }}/16/86/{{ file_hash }}/virtualenv-1.7.2.tar.gz" - md5: "b5d63b05373a4344ae099a68875aae78" + url: "{{ pkg_url }}/16/86/{{ venv_url_hashes.py24 }}/virtualenv-1.7.2.tar.gz" + md5: "{{ venv_file_hashes.py24 }}" tar_file: "/tmp/virtualenv-{{ venv_versions.py24 }}.tar.gz" sources: "/tmp/virtualenv-{{ venv_versions.py24 }}" venv26: version: "{{ venv_versions.py26 }}" - file_hash: "f425e456e017af4801bb08920e30c149a44ac0c194f2225bdb712e77701c" - url: "{{ pkg_url }}/d5/5b/{{ file_hash }}/virtualenv-1.10.tar.gz" - md5: "9745c28256c70c76d36adb3767a00212" + url: "{{ pkg_url }}/d5/5b/{{ venv_url_hashes.py26 }}/virtualenv-1.10.tar.gz" + md5: "{{ venv_file_hashes.py26 }}" tar_file: "/tmp/virtualenv-{{ venv_versions.py26 }}.tar.gz" sources: "/tmp/virtualenv-{{ venv_versions.py26 }}" venv27: version: "{{ venv_versions.py27 }}" - file_hash: "706af3ee62032933a3217454609c50a5325a6bd9c2c2f495b58c456ba286" - url: "{{ pkg_url }}/37/27/{{ file_hash }}/virtualenv-16.6.1.tar.gz" - md5: "b05b03dc6ecb3caaa3d58bfcccf4e786" - tar_file: "/tmp/virtualenv-{{ venv_versions.py27 }}.tar.gz" - sources: "/tmp/virtualenv-{{ venv_versions.py27 }}" + url: "{{ pkg_url }}/6f/43/{{ venv_url_hashes.py27 }}/{{ venv27_wheel_name }}" + md5: "{{ venv_file_hashes.py27 }}" + wheel_file: "/tmp/{{ venv27_wheel_name }}" From 2936bb33f1ea2ee31785d1f51704b55d73386b8b Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Sun, 12 May 2024 10:18:54 +0200 Subject: [PATCH 3/4] fix(venvs): remove non-existing variable --- tasks/venv.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tasks/venv.yml b/tasks/venv.yml index 576d3ce..6d9c882 100644 --- a/tasks/venv.yml +++ b/tasks/venv.yml @@ -6,7 +6,6 @@ path: "{{ py_data.install }}/bin/virtualenv" register: already_installed ignore_errors: true - when: should_install - name: "Virtualenv | Download | {{ py_data.version }}" ansible.builtin.get_url: @@ -14,14 +13,14 @@ dest: "{{ venv_data.tar_file }}" checksum: "md5:{{ venv_data.md5 }}" mode: "0440" - when: should_install and not already_installed.stat.exists + when: not already_installed.stat.exists - name: "Virtualenv | Uncompress | {{ py_data.version }}" ansible.builtin.unarchive: src: "{{ venv_data.tar_file }}" dest: /tmp copy: false - when: should_install and not already_installed.stat.exists + when: not already_installed.stat.exists - name: " Virtualenv | Install | {{ py_data.version }}" become: true @@ -31,4 +30,4 @@ creates: "{{ py_data.install }}/bin/virtualenv" with_items: - "{{ py_data.bin }} setup.py install" - when: should_install and not already_installed.stat.exists + when: not already_installed.stat.exists From a322440adcc9104f93844f88c319a5edc8a83f88 Mon Sep 17 00:00:00 2001 From: Gil Forcada Codinachs Date: Sun, 12 May 2024 10:19:11 +0200 Subject: [PATCH 4/4] feat(venvs): split python 2.7 venv creation Install `virtualenv` with `pip` to ensure it works. --- tasks/venv27.yml | 41 +++++++++++++++++++++++++++++++++++++++++ tasks/venvs.yml | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tasks/venv27.yml diff --git a/tasks/venv27.yml b/tasks/venv27.yml new file mode 100644 index 0000000..d13408b --- /dev/null +++ b/tasks/venv27.yml @@ -0,0 +1,41 @@ +--- + +- name: "Virtualenv | Check if it is already installed | {{ py_data.version }}" + become: true + ansible.builtin.stat: + path: "{{ py_data.install }}/bin/virtualenv" + register: already_installed + ignore_errors: true + +- name: "Virtualenv | Download | {{ py_data.version }}" + ansible.builtin.get_url: + url: "{{ venv_data.url }}" + dest: "{{ venv_data.wheel_file }}" + checksum: "md5:{{ venv_data.md5 }}" + mode: "0440" + when: not already_installed.stat.exists + +- name: "Virtualenv | Download | pip" + ansible.builtin.get_url: + url: "https://bootstrap.pypa.io/pip/2.7/get-pip.py" + dest: "/tmp/get-pip.py" + checksum: "md5:60e8267eb1b7bc71dc4843eb7bd294d3" + mode: "0440" + when: not already_installed.stat.exists + +- name: "Virtualenv | Install | pip" + ansible.builtin.command: "{{ item }}" + args: + creates: "{{ py_data.install }}/bin/pip" + with_items: + - "{{ py_data.install }}/bin/python /tmp/get-pip.py" + when: not already_installed.stat.exists + +- name: " Virtualenv | Install | {{ py_data.version }}" + become: true + ansible.builtin.command: "{{ item }}" + args: + creates: "{{ py_data.install }}/bin/virtualenv" + with_items: + - "{{ py_data.install }}/bin/pip install {{ venv_data.wheel_file }}" + when: not already_installed.stat.exists diff --git a/tasks/venvs.yml b/tasks/venvs.yml index c28511b..f3cc48b 100644 --- a/tasks/venvs.yml +++ b/tasks/venvs.yml @@ -18,7 +18,7 @@ - name: Install Virtualenv for Python 2.7 ansible.builtin.include_tasks: - file: venv.yml + file: venv27.yml vars: py_data: "{{ py27 }}" venv_data: "{{ venv27 }}"