Skip to content

Commit 3871357

Browse files
committed
Don't clobber system Python
Install python-openstackclient in a venv for community_images operations
1 parent e70cc3d commit 3871357

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

roles/community_images/defaults/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
---
2+
# The path to the venv that python dependencies will be installed
3+
# in
4+
community_images_venv_path: /opt/community-images-venv
5+
6+
# The path to the openstack cli executable
7+
community_images_openstack_cli_path: >-
8+
{{ community_images_venv_path }}/bin/openstack
29
310
# The directory into which images will be downloaded / converted
411
# 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
@@ -14,13 +14,15 @@
1414
ansible.builtin.apt:
1515
name:
1616
- python3-pip
17+
- python3-venv
1718
- qemu-utils
1819
state: present
1920

2021
- name: Ensure OpenStack CLI (and SDK) are available
2122
ansible.builtin.pip:
2223
name: python-openstackclient
23-
executable: pip3
24+
virtualenv: "{{ community_images_venv_path }}"
25+
virtualenv_command: python3 -m venv
2426

2527
- name: Ensure OpenStack config directory exists
2628
ansible.builtin.file:

roles/community_images/tasks/upload_image.yml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
mode: "0755"
2424

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

@@ -39,7 +42,10 @@
3942
community_images_image_id: "{{ community_images_image_list | map(attribute='ID') | first }}"
4043

4144
- name: "Fetch pre-existing image - {{ community_images_image_spec.name }}"
42-
ansible.builtin.command: "openstack image show -f json {{ community_images_image_id }}"
45+
ansible.builtin.command: >-
46+
{{ community_images_openstack_cli_path }}
47+
image show -f json
48+
{{ community_images_image_id }}
4349
changed_when: false
4450
register: community_images_image_info
4551

@@ -109,7 +115,7 @@
109115
# Instead, we use the OpenStack CLI directly
110116
- name: "Upload image - {{ community_images_image_spec.name }}"
111117
ansible.builtin.command: >-
112-
openstack image create
118+
{{ community_images_openstack_cli_path }} image create
113119
-f json
114120
--container-format {{ community_images_image_spec.container_format }}
115121
--disk-format {{ community_images_disk_format }}
@@ -145,14 +151,18 @@
145151
146152
- name: "Set image visibility - {{ community_images_image_spec.name }}"
147153
ansible.builtin.command: >-
148-
openstack image set --{{ community_images_image_visibility }} {{ community_images_image_id }}
154+
{{ community_images_openstack_cli_path }}
155+
image set
156+
--{{ community_images_image_visibility }}
157+
{{ community_images_image_id }}
149158
when: community_images_image_visibility != community_images_image_current_visibility
150159
changed_when: true
151160

152161
- name: "Set custom properties for image - {{ community_images_image_spec.name }}"
153162
ansible.builtin.command: >-
154-
openstack image set
155-
{%- for property in community_images_custom_properties %}
163+
{{ community_images_openstack_cli_path }}
164+
image set
165+
{%- for property in community_images_custom_properties %}
156166
--property {{ property | quote }}
157167
{%- endfor %}
158168
{{ community_images_image_id }}
@@ -163,7 +173,10 @@
163173
when: "community_images_image_visibility == 'shared'"
164174
block:
165175
- name: "Share image with project - {{ community_images_image_spec.name }}"
166-
ansible.builtin.command: "openstack image add project {{ community_images_image_id }} {{ project_id }}"
176+
ansible.builtin.command: >-
177+
{{ community_images_openstack_cli_path }}
178+
image add project
179+
{{ community_images_image_id }} {{ project_id }}
167180
register: community_images_image_add_project
168181
changed_when: community_images_image_add_project.rc == 0
169182
failed_when: >-
@@ -174,7 +187,10 @@
174187
loop_var: project_id
175188

176189
- name: "Accept image into project - {{ community_images_image_spec.name }}"
177-
ansible.builtin.command: "openstack image set --accept {{ community_images_image_id }}"
190+
ansible.builtin.command: >-
191+
{{ community_images_openstack_cli_path }}
192+
image set
193+
--accept {{ community_images_image_id }}
178194
environment:
179195
OS_CLOUD: "{{ project_key }}"
180196
loop: "{{ community_images_share_projects | map(attribute='key') | list }}"

roles/infra/tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
name: azimuth_cloud.azimuth_ops.community_images
1414
tasks_from: upload_image
1515
vars:
16+
community_images_openstack_cli_path: openstack
1617
community_images_image_spec:
1718
name: "{{ infra_image_name }}"
1819
source_url: "{{ infra_image_source_url }}"

0 commit comments

Comments
 (0)