From d0d4a3ed2b5dacf96988220ad1e262510ca50741 Mon Sep 17 00:00:00 2001 From: Gil Forcada Date: Sun, 17 Jun 2018 19:28:53 +0200 Subject: [PATCH] Refactor virutalenv yml to be reusable --- defaults/main.yml | 38 +++++++++------- tasks/main.yml | 5 ++- tasks/venv.yml | 112 +++++++--------------------------------------- 3 files changed, 43 insertions(+), 112 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 18a5e8e..87ea40e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -20,6 +20,11 @@ versions: py35: "3.5.5" py36: "3.6.5" +venv_versions: + py24: "1.7.2" + py26: "1.10" + py27: "16.0.0" + ## # fine grained settings ## @@ -75,20 +80,23 @@ py36: install: "{{ base_install_folder }}/python{{ versions.py36 }}" bin: "{{ base_install_folder }}/python{{ versions.py36 }}/bin/python3.6" -venv24_version: "1.7.2" -venv24_url: "https://files.pythonhosted.org/packages/16/86/7b88d35d0a353ec70e42aa37fd8b0bd1c643419c80f022ffaafa4d6449f0/virtualenv-1.7.2.tar.gz" -venv24_md5: "b5d63b05373a4344ae099a68875aae78" -venv24_tar_file: "/tmp/virtualenv-{{ venv26_version }}.tar.gz" -venv24_sources: "/tmp/virtualenv-{{ venv26_version }}" +venv24: + version: "{{ venv_versions.py24 }}" + url: "https://files.pythonhosted.org/packages/16/86/7b88d35d0a353ec70e42aa37fd8b0bd1c643419c80f022ffaafa4d6449f0/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: "1.10" -venv26_url: "https://files.pythonhosted.org/packages/d5/5b/f425e456e017af4801bb08920e30c149a44ac0c194f2225bdb712e77701c/virtualenv-1.10.tar.gz" -venv26_md5: "9745c28256c70c76d36adb3767a00212" -venv26_tar_file: "/tmp/virtualenv-{{ venv26_version }}.tar.gz" -venv26_sources: "/tmp/virtualenv-{{ venv26_version }}" +venv26: + version: "{{ venv_versions.py26 }}" + url: "https://files.pythonhosted.org/packages/d5/5b/f425e456e017af4801bb08920e30c149a44ac0c194f2225bdb712e77701c/virtualenv-1.10.tar.gz" + md5: "9745c28256c70c76d36adb3767a00212" + tar_file: "/tmp/virtualenv-{{ venv_versions.py26 }}.tar.gz" + sources: "/tmp/virtualenv-{{ venv_versions.py26 }}" -venv27_version: "16.0.0" -venv27_url: "https://files.pythonhosted.org/packages/33/bc/fa0b5347139cd9564f0d44ebd2b147ac97c36b2403943dbee8a25fd74012/virtualenv-16.0.0.tar.gz" -venv27_md5: "4feb74ee26255dd7e62e36ce96bcc4c6" -venv27_tar_file: "/tmp/virtualenv-{{ venv27_version }}.tar.gz" -venv27_sources: "/tmp/virtualenv-{{ venv27_version }}" +venv27: + version: "{{ venv_versions.py27 }}" + url: "https://files.pythonhosted.org/packages/33/bc/fa0b5347139cd9564f0d44ebd2b147ac97c36b2403943dbee8a25fd74012/virtualenv-16.0.0.tar.gz" + md5: "4feb74ee26255dd7e62e36ce96bcc4c6" + tar_file: "/tmp/virtualenv-{{ venv_versions.py27 }}.tar.gz" + sources: "/tmp/virtualenv-{{ venv_versions.py27 }}" diff --git a/tasks/main.yml b/tasks/main.yml index afb386d..a7e5f8f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -6,5 +6,6 @@ - include: python_generic.yml py_data={{ py27 }} should_install={{ python_27 }} - include: python_generic.yml py_data={{ py35 }} should_install={{ python_35 }} - include: python_generic.yml py_data={{ py36 }} should_install={{ python_36 }} -- include: venv.yml - +- include: venv.yml py_data={{ py24 }} venv_data={{ venv24 }} should_install={{ python_24 }} +- include: venv.yml py_data={{ py26 }} venv_data={{ venv26 }} should_install={{ python_26 }} +- include: venv.yml py_data={{ py27 }} venv_data={{ venv27 }} should_install={{ python_27 }} diff --git a/tasks/venv.yml b/tasks/venv.yml index fd9ee2e..4c3eb2d 100644 --- a/tasks/venv.yml +++ b/tasks/venv.yml @@ -1,110 +1,32 @@ --- -## -# Check if virtualenv is already installed -## - -- name: virtualenv 2.4 | Check if virtualenv is already installed - become: true - stat: path="{{ py24_install }}/bin/virtualenv" - register: virtualenv24_already_installed - ignore_errors: True - when: python_24 - -- name: virtualenv 2.6 | Check if virtualenv is already installed +- name: "virtualenv for {{ py_data.version }} | Check if virtualenv is already installed" become: true - stat: path="{{ py26_install }}/bin/virtualenv" - register: virtualenv26_already_installed + stat: path="{{ py_data.install }}/bin/virtualenv" + register: already_installed ignore_errors: True - when: python_26 - -- name: virtualenv 2.7 | Check if virtualenv is already installed - become: true - stat: path="{{ py27_install }}/bin/virtualenv" - register: virtualenv27_already_installed - ignore_errors: True - when: python_27 - -## -# Download -## + when: should_install -- name: virtualenv for 2.4 | Download +- name: "virtualenv for {{ py_data.version }} | Download" get_url: - url="{{ venv24_url }}" - dest="{{ venv24_tar_file }}" - checksum="md5:{{ venv24_md5 }}" - when: python_24 and virtualenv24_already_installed.stat.exists == false - -- name: virtualenv for 2.6 | Download - get_url: - url="{{ venv26_url }}" - dest="{{ venv26_tar_file }}" - checksum="md5:{{ venv26_md5 }}" - when: python_26 and virtualenv26_already_installed.stat.exists == false - -- name: virtualenv for 2.7 | Download - get_url: - url="{{ venv27_url }}" - dest="{{ venv27_tar_file }}" - checksum="md5:{{ venv27_md5 }}" - when: python_27 and virtualenv27_already_installed.stat.exists == false - -## -# Uncompress -## - -- name: virtualenv for 2.4 | Uncompress - unarchive: - src="{{ venv24_tar_file }}" - dest=/tmp - copy=no - when: python_24 and virtualenv24_already_installed.stat.exists == false - -- name: virtualenv for 2.6 | Uncompress - unarchive: - src="{{ venv26_tar_file }}" - dest=/tmp - copy=no - when: python_26 and virtualenv26_already_installed.stat.exists == false + url="{{ venv_data.url }}" + dest="{{ venv_data.tar_file }}" + checksum="md5:{{ venv_data.md5 }}" + when: should_install and already_installed.stat.exists == false -- name: virtualenv for 2.7 | Uncompress +- name: "virtualenv for {{ py_data.version }} | Uncompress" unarchive: - src="{{ venv27_tar_file }}" + src="{{ venv_data.tar_file }}" dest=/tmp copy=no - when: python_27 and virtualenv27_already_installed.stat.exists == false - -## -# Install -## - -- name: py24 | Install virtualenv - become: true - command: "{{ item }}" - args: - chdir: "{{ venv24_sources }}" - creates: "{{ py24_install }}/bin/virtualenv" - with_items: - - "{{ py24_bin }} setup.py install" - when: python_24 and virtualenv24_already_installed.stat.exists == false - -- name: py26 | Install virtualenv - become: true - command: "{{ item }}" - args: - chdir: "{{ venv26_sources }}" - creates: "{{ py26_install }}/bin/virtualenv" - with_items: - - "{{ py26_bin }} setup.py install" - when: python_26 and virtualenv26_already_installed.stat.exists == false + when: should_install and already_installed.stat.exists == false -- name: py27 | Install virtualenv +- name: " {{ py_data.version }} | Install virtualenv" become: true command: "{{ item }}" args: - chdir: "{{ venv27_sources }}" - creates: "{{ py27_install }}/bin/virtualenv" + chdir: "{{ venv_data.sources }}" + creates: "{{ py_data.install }}/bin/virtualenv" with_items: - - "{{ py27_bin }} setup.py install" - when: python_27 and virtualenv27_already_installed.stat.exists == false + - "{{ py_data.bin }} setup.py install" + when: should_install and already_installed.stat.exists == false