Skip to content

Commit 9023d37

Browse files
committed
Don't clobber system Python
Install python-openstackclient in a venv for community_images operations
1 parent 9fd442f commit 9023d37

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

roles/community_images/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
# The path to the venv that python dependencies will be installed
3+
# in
4+
community_images_venv_path: /opt/community-images-venv
25

36
# The directory into which images will be downloaded / converted
47
# If not given, a temporary directory will be used

roles/community_images/tasks/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
apt:
1414
name:
1515
- python3-pip
16+
- python3-venv
1617
- qemu-utils
1718
state: present
1819

1920
- name: Ensure OpenStack CLI (and SDK) are available
2021
pip:
2122
name: python-openstackclient
22-
executable: pip3
23+
virtualenv: "{{ community_images_venv_path }}"
24+
virtualenv_command: python3 -m venv
2325
become: yes
2426

2527
- name: Ensure OpenStack config directory exists

roles/community_images/tasks/upload_image.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
path: "{{ community_images_workdir }}"
2424

2525
- name: "List images with name - {{ community_images_image_spec.name }}"
26-
command: "openstack image list -f json --name {{ community_images_image_spec.name }}"
26+
command: >-
27+
{{ community_images_venv_path }}/bin/openstack
28+
image list -f json
29+
--name {{ community_images_image_spec.name }}
2730
changed_when: false
2831
register: community_images_image_list_cmd
2932

@@ -37,7 +40,10 @@
3740
community_images_image_id: "{{ community_images_image_list | map(attribute = 'ID') | first }}"
3841

3942
- name: "Fetch pre-existing image - {{ community_images_image_spec.name }}"
40-
command: "openstack image show -f json {{ community_images_image_id }}"
43+
command: >-
44+
{{ community_images_venv_path }}/bin/openstack
45+
image show -f json
46+
{{ community_images_image_id }}
4147
changed_when: false
4248
register: community_images_image_info
4349

@@ -105,7 +111,7 @@
105111
# Instead, we use the OpenStack CLI directly
106112
- name: "Upload image - {{ community_images_image_spec.name }}"
107113
command: >-
108-
openstack image create
114+
{{ community_images_venv_path }}/bin/openstack image create
109115
-f json
110116
--container-format {{ community_images_image_spec.container_format }}
111117
--disk-format {{ community_images_disk_format }}
@@ -141,12 +147,15 @@
141147
142148
- name: "Set image visibility - {{ community_images_image_spec.name }}"
143149
command: >-
144-
openstack image set --{{ community_images_image_visibility }} {{ community_images_image_id }}
150+
{{ community_images_venv_path }}/bin/openstack
151+
image set
152+
--{{ community_images_image_visibility }}
153+
{{ community_images_image_id }}
145154
when: community_images_image_visibility != community_images_image_current_visibility
146155

147156
- name: "Set custom properties for image - {{ community_images_image_spec.name }}"
148157
command: >-
149-
openstack image set
158+
{{ community_images_venv_path }}/bin/openstack image set
150159
{%- for property in community_images_custom_properties %}
151160
--property {{ property | quote }}
152161
{%- endfor %}
@@ -155,7 +164,10 @@
155164

156165
- block:
157166
- name: "Share image with project - {{ community_images_image_spec.name }}"
158-
command: "openstack image add project {{ community_images_image_id }} {{ project_id }}"
167+
command: >-
168+
{{ community_images_venv_path }}/bin/openstack
169+
image add project
170+
{{ community_images_image_id }} {{ project_id }}
159171
register: community_images_image_add_project
160172
changed_when: community_images_image_add_project.rc == 0
161173
failed_when: >-
@@ -166,7 +178,10 @@
166178
loop_var: project_id
167179

168180
- name: "Accept image into project - {{ community_images_image_spec.name }}"
169-
command: "openstack image set --accept {{ community_images_image_id }}"
181+
command: >-
182+
{{ community_images_venv_path }}/bin/openstack
183+
image set
184+
--accept {{ community_images_image_id }}
170185
environment:
171186
OS_CLOUD: "{{ project_key }}"
172187
loop: "{{ community_images_share_projects | map(attribute = 'key') | list }}"

0 commit comments

Comments
 (0)