Skip to content

Commit 2adac48

Browse files
committed
Adds os_virtualenv_python
This sets the collection wide python interpretter. This can also be set on a per role basis with: - os_openstackclient_virtualenv_python - os_openstacksdk_virtualenv_python Also adds: - os_openstackclient_virtualenv_command Depending on the version of upper constraints, you may need to use a newer python interpreter.
1 parent 47b2eba commit 2adac48

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

roles/os_openstackclient/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
os_openstackclient_venv:
44
# Whether to install package dependencies.
55
os_openstackclient_install_package_dependencies: true
6+
# Value to use for the pip module's `virtualenv_command` argument when creating the virtualenv
7+
os_openstackclient_virtualenv_command: "{{ os_openstackclient_virtualenv_python ~ ' -m venv' if os_openstackclient_venv else omit }}"
8+
# Python interpreter to use in virtualenv command; `os_virtualenv_python` can be used to set this collection wide.
9+
os_openstackclient_virtualenv_python: "{{ os_virtualenv_python | default('python3.' ~ ansible_facts.python.version.minor) }}"
610

711
# State of the openstackclient package.
812
os_openstackclient_state: present

roles/os_openstackclient/tasks/main.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
become: "{{ ansible_facts.system != 'Darwin' }}"
1515
when: os_openstackclient_install_package_dependencies | bool
1616

17+
- name: Remove virtualenv if python version is stale
18+
file:
19+
path: "{{ os_openstackclient_venv }}"
20+
state: absent
21+
when:
22+
- os_openstackclient_venv is not none
23+
- (os_openstackclient_venv ~ '/bin/python') | realpath != os_openstackclient_virtualenv_python | realpath
24+
1725
- name: Ensure the virtualenv directory exists
1826
when: os_openstackclient_venv is not none
1927
block:
@@ -40,7 +48,7 @@
4048
name: "{{ item.name }}"
4149
state: latest
4250
virtualenv: "{{ os_openstackclient_venv or omit }}"
43-
virtualenv_command: "{{ 'python3.' ~ ansible_facts.python.version.minor ~ ' -m venv' if os_openstackclient_venv else omit }}"
51+
virtualenv_command: "{{ os_openstackclient_virtualenv_command }}"
4452
with_items:
4553
- { name: pip }
4654
- { name: setuptools }

roles/os_openstacksdk/defaults/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# Path to a directory in which to create a virtualenv.
33
os_openstacksdk_venv:
44
# Value to use for the pip module's `virtualenv_command` argument when creating the virtualenv
5-
os_openstacksdk_virtualenv_command: "{{ 'python3.' ~ ansible_facts.python.version.minor ~ ' -m venv' if os_openstacksdk_venv else omit }}"
5+
os_openstacksdk_virtualenv_command: "{{ os_openstacksdk_virtualenv_python ~ ' -m venv' if os_openstacksdk_venv else omit }}"
6+
# Python interpreter to use in virtualenv command; `os_virtualenv_python` can be used to set this collection wide.
7+
os_openstacksdk_virtualenv_python: "{{ os_virtualenv_python | default('python3.' ~ ansible_facts.python.version.minor) }}"
68

79
# Whether to install package dependencies.
810
os_openstacksdk_install_package_dependencies: true

roles/os_openstacksdk/tasks/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
become: "{{ ansible_facts.system != 'Darwin' }}"
2121
when: os_openstacksdk_install_package_dependencies | bool
2222

23+
- name: Remove virtualenv if python version is stale
24+
file:
25+
path: "{{ os_openstacksdk_venv }}"
26+
state: absent
27+
when:
28+
- os_openstacksdk_venv is not none
29+
- (os_openstacksdk_venv ~ '/bin/python') | realpath != os_openstacksdk_virtualenv_python | realpath
30+
2331
- name: Ensure the virtualenv directory exists
2432
when: os_openstacksdk_venv is not none
2533
block:

0 commit comments

Comments
 (0)