Skip to content

Commit d0d4a3e

Browse files
committed
Refactor virutalenv yml to be reusable
1 parent 9148746 commit d0d4a3e

File tree

3 files changed

+43
-112
lines changed

3 files changed

+43
-112
lines changed

defaults/main.yml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ versions:
2020
py35: "3.5.5"
2121
py36: "3.6.5"
2222

23+
venv_versions:
24+
py24: "1.7.2"
25+
py26: "1.10"
26+
py27: "16.0.0"
27+
2328
##
2429
# fine grained settings
2530
##
@@ -75,20 +80,23 @@ py36:
7580
install: "{{ base_install_folder }}/python{{ versions.py36 }}"
7681
bin: "{{ base_install_folder }}/python{{ versions.py36 }}/bin/python3.6"
7782

78-
venv24_version: "1.7.2"
79-
venv24_url: "https://files.pythonhosted.org/packages/16/86/7b88d35d0a353ec70e42aa37fd8b0bd1c643419c80f022ffaafa4d6449f0/virtualenv-1.7.2.tar.gz"
80-
venv24_md5: "b5d63b05373a4344ae099a68875aae78"
81-
venv24_tar_file: "/tmp/virtualenv-{{ venv26_version }}.tar.gz"
82-
venv24_sources: "/tmp/virtualenv-{{ venv26_version }}"
83+
venv24:
84+
version: "{{ venv_versions.py24 }}"
85+
url: "https://files.pythonhosted.org/packages/16/86/7b88d35d0a353ec70e42aa37fd8b0bd1c643419c80f022ffaafa4d6449f0/virtualenv-1.7.2.tar.gz"
86+
md5: "b5d63b05373a4344ae099a68875aae78"
87+
tar_file: "/tmp/virtualenv-{{ {{ venv_versions.py24 }} }}.tar.gz"
88+
sources: "/tmp/virtualenv-{{ {{ venv_versions.py24 }} }}"
8389

84-
venv26_version: "1.10"
85-
venv26_url: "https://files.pythonhosted.org/packages/d5/5b/f425e456e017af4801bb08920e30c149a44ac0c194f2225bdb712e77701c/virtualenv-1.10.tar.gz"
86-
venv26_md5: "9745c28256c70c76d36adb3767a00212"
87-
venv26_tar_file: "/tmp/virtualenv-{{ venv26_version }}.tar.gz"
88-
venv26_sources: "/tmp/virtualenv-{{ venv26_version }}"
90+
venv26:
91+
version: "{{ venv_versions.py26 }}"
92+
url: "https://files.pythonhosted.org/packages/d5/5b/f425e456e017af4801bb08920e30c149a44ac0c194f2225bdb712e77701c/virtualenv-1.10.tar.gz"
93+
md5: "9745c28256c70c76d36adb3767a00212"
94+
tar_file: "/tmp/virtualenv-{{ venv_versions.py26 }}.tar.gz"
95+
sources: "/tmp/virtualenv-{{ venv_versions.py26 }}"
8996

90-
venv27_version: "16.0.0"
91-
venv27_url: "https://files.pythonhosted.org/packages/33/bc/fa0b5347139cd9564f0d44ebd2b147ac97c36b2403943dbee8a25fd74012/virtualenv-16.0.0.tar.gz"
92-
venv27_md5: "4feb74ee26255dd7e62e36ce96bcc4c6"
93-
venv27_tar_file: "/tmp/virtualenv-{{ venv27_version }}.tar.gz"
94-
venv27_sources: "/tmp/virtualenv-{{ venv27_version }}"
97+
venv27:
98+
version: "{{ venv_versions.py27 }}"
99+
url: "https://files.pythonhosted.org/packages/33/bc/fa0b5347139cd9564f0d44ebd2b147ac97c36b2403943dbee8a25fd74012/virtualenv-16.0.0.tar.gz"
100+
md5: "4feb74ee26255dd7e62e36ce96bcc4c6"
101+
tar_file: "/tmp/virtualenv-{{ venv_versions.py27 }}.tar.gz"
102+
sources: "/tmp/virtualenv-{{ venv_versions.py27 }}"

tasks/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
- include: python_generic.yml py_data={{ py27 }} should_install={{ python_27 }}
77
- include: python_generic.yml py_data={{ py35 }} should_install={{ python_35 }}
88
- include: python_generic.yml py_data={{ py36 }} should_install={{ python_36 }}
9-
- include: venv.yml
10-
9+
- include: venv.yml py_data={{ py24 }} venv_data={{ venv24 }} should_install={{ python_24 }}
10+
- include: venv.yml py_data={{ py26 }} venv_data={{ venv26 }} should_install={{ python_26 }}
11+
- include: venv.yml py_data={{ py27 }} venv_data={{ venv27 }} should_install={{ python_27 }}

tasks/venv.yml

Lines changed: 17 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,32 @@
11
---
22

3-
##
4-
# Check if virtualenv is already installed
5-
##
6-
7-
- name: virtualenv 2.4 | Check if virtualenv is already installed
8-
become: true
9-
stat: path="{{ py24_install }}/bin/virtualenv"
10-
register: virtualenv24_already_installed
11-
ignore_errors: True
12-
when: python_24
13-
14-
- name: virtualenv 2.6 | Check if virtualenv is already installed
3+
- name: "virtualenv for {{ py_data.version }} | Check if virtualenv is already installed"
154
become: true
16-
stat: path="{{ py26_install }}/bin/virtualenv"
17-
register: virtualenv26_already_installed
5+
stat: path="{{ py_data.install }}/bin/virtualenv"
6+
register: already_installed
187
ignore_errors: True
19-
when: python_26
20-
21-
- name: virtualenv 2.7 | Check if virtualenv is already installed
22-
become: true
23-
stat: path="{{ py27_install }}/bin/virtualenv"
24-
register: virtualenv27_already_installed
25-
ignore_errors: True
26-
when: python_27
27-
28-
##
29-
# Download
30-
##
8+
when: should_install
319

32-
- name: virtualenv for 2.4 | Download
10+
- name: "virtualenv for {{ py_data.version }} | Download"
3311
get_url:
34-
url="{{ venv24_url }}"
35-
dest="{{ venv24_tar_file }}"
36-
checksum="md5:{{ venv24_md5 }}"
37-
when: python_24 and virtualenv24_already_installed.stat.exists == false
38-
39-
- name: virtualenv for 2.6 | Download
40-
get_url:
41-
url="{{ venv26_url }}"
42-
dest="{{ venv26_tar_file }}"
43-
checksum="md5:{{ venv26_md5 }}"
44-
when: python_26 and virtualenv26_already_installed.stat.exists == false
45-
46-
- name: virtualenv for 2.7 | Download
47-
get_url:
48-
url="{{ venv27_url }}"
49-
dest="{{ venv27_tar_file }}"
50-
checksum="md5:{{ venv27_md5 }}"
51-
when: python_27 and virtualenv27_already_installed.stat.exists == false
52-
53-
##
54-
# Uncompress
55-
##
56-
57-
- name: virtualenv for 2.4 | Uncompress
58-
unarchive:
59-
src="{{ venv24_tar_file }}"
60-
dest=/tmp
61-
copy=no
62-
when: python_24 and virtualenv24_already_installed.stat.exists == false
63-
64-
- name: virtualenv for 2.6 | Uncompress
65-
unarchive:
66-
src="{{ venv26_tar_file }}"
67-
dest=/tmp
68-
copy=no
69-
when: python_26 and virtualenv26_already_installed.stat.exists == false
12+
url="{{ venv_data.url }}"
13+
dest="{{ venv_data.tar_file }}"
14+
checksum="md5:{{ venv_data.md5 }}"
15+
when: should_install and already_installed.stat.exists == false
7016

71-
- name: virtualenv for 2.7 | Uncompress
17+
- name: "virtualenv for {{ py_data.version }} | Uncompress"
7218
unarchive:
73-
src="{{ venv27_tar_file }}"
19+
src="{{ venv_data.tar_file }}"
7420
dest=/tmp
7521
copy=no
76-
when: python_27 and virtualenv27_already_installed.stat.exists == false
77-
78-
##
79-
# Install
80-
##
81-
82-
- name: py24 | Install virtualenv
83-
become: true
84-
command: "{{ item }}"
85-
args:
86-
chdir: "{{ venv24_sources }}"
87-
creates: "{{ py24_install }}/bin/virtualenv"
88-
with_items:
89-
- "{{ py24_bin }} setup.py install"
90-
when: python_24 and virtualenv24_already_installed.stat.exists == false
91-
92-
- name: py26 | Install virtualenv
93-
become: true
94-
command: "{{ item }}"
95-
args:
96-
chdir: "{{ venv26_sources }}"
97-
creates: "{{ py26_install }}/bin/virtualenv"
98-
with_items:
99-
- "{{ py26_bin }} setup.py install"
100-
when: python_26 and virtualenv26_already_installed.stat.exists == false
22+
when: should_install and already_installed.stat.exists == false
10123

102-
- name: py27 | Install virtualenv
24+
- name: " {{ py_data.version }} | Install virtualenv"
10325
become: true
10426
command: "{{ item }}"
10527
args:
106-
chdir: "{{ venv27_sources }}"
107-
creates: "{{ py27_install }}/bin/virtualenv"
28+
chdir: "{{ venv_data.sources }}"
29+
creates: "{{ py_data.install }}/bin/virtualenv"
10830
with_items:
109-
- "{{ py27_bin }} setup.py install"
110-
when: python_27 and virtualenv27_already_installed.stat.exists == false
31+
- "{{ py_data.bin }} setup.py install"
32+
when: should_install and already_installed.stat.exists == false

0 commit comments

Comments
 (0)