Skip to content

Commit 678d196

Browse files
testing
1 parent 5693db4 commit 678d196

2 files changed

Lines changed: 112 additions & 86 deletions

File tree

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,54 @@
11
---
22

3-
# List of images to upload to Glance
4-
understack_images: []
5-
# - uuid: "d3a91716-9014-4f47-a05c-01994f6aa0e3"
6-
# name: "Talos 1.10.5"
7-
# description: "Talos Linux 1.10.5 image"
8-
# external_url: "https://example.com/images/talos-1.10.5-amd64.raw"
9-
# checksum: "sha256:abc123..." # optional
10-
# tags:
11-
# - talos
12-
# - linux
13-
# is_public: true
14-
# is_protected: false
15-
# disk_format: raw
16-
# container_format: bare
17-
# min_disk: 0
18-
# min_ram: 0
19-
# properties:
20-
# img_config_drive: mandatory
21-
# os_distro: talos
22-
# os_version: "1.10.5"
23-
24-
25-
# understack_images:
26-
# - uuid: 55676f77-e96c-482e-a77a-d52ced4e8247
27-
# name: Talos 1.10.5 - Nick test
28-
# description: Talos Linux 1.10.5 image - Nick test
29-
# external_url: https://factory.talos.dev/image/96f8c146a67c80daad900d3fc1a6976fe11062321eee9ab6ae2a6aea88b2d26e/v1.10.5/openstack-amd64.raw.xz
30-
# # checksum: "sha256:abc123..." # optional
31-
# tags:
32-
# - talos
33-
# - linux
34-
# is_public: true
35-
# is_protected: false
36-
# disk_format: raw
37-
# container_format: bare
38-
# min_disk: 0
39-
# min_ram: 0
40-
# properties:
41-
# img_config_drive: mandatory
42-
# os_distro: talos
43-
# os_version: 1.10.5
44-
45-
463
# Temporary directory for downloading images
474
image_download_dir: "/tmp/glance_images"
485

49-
# OpenStack cloud configuration (should be set in playbook or inventory)
50-
# openstack_cloud: "default"
6+
# List of images to upload to Glance
7+
understack_images:
8+
- uuid: 00000000-0000-0000-1111-000000000000
9+
name: esp.img
10+
description: EFI system partition image from understack-images-20251016184704
11+
external_url: https://github.com/rackerlabs/understack/releases/download/understack-images-20251016184704/esp.img
12+
is_public: false
13+
is_protected: false
14+
disk_format: raw
15+
container_format: bare
16+
min_disk: 0
17+
min_ram: 0
18+
properties: {}
19+
- uuid: 00000000-0000-0000-2222-000000000000
20+
name: ipa-debian-bookworm.kernel
21+
description: IPA Debian Bookworm kernel image from understack-images-20251016184704
22+
external_url: https://github.com/rackerlabs/understack/releases/download/understack-images-20251016184704/ipa-debian-bookworm.kernel
23+
is_public: false
24+
is_protected: false
25+
disk_format: raw
26+
container_format: bare
27+
min_disk: 0
28+
min_ram: 0
29+
properties: {}
30+
- uuid: 00000000-0000-0000-3333-000000000000
31+
name: ipa-debian-bookworm.initramfs
32+
description: IPA Debian Bookworm initramfs image from understack-images-20251016184704
33+
external_url: https://github.com/rackerlabs/understack/releases/download/understack-images-20251016184704/ipa-debian-bookworm.initramfs
34+
is_public: false
35+
is_protected: false
36+
disk_format: raw
37+
container_format: bare
38+
min_disk: 0
39+
min_ram: 0
40+
properties: {}
41+
- uuid: 00000000-0000-0000-4444-000000000000
42+
name: Ubuntu 24.04
43+
description: Ubuntu Noble qcow2 image from understack-images-20251016184704
44+
external_url: https://github.com/rackerlabs/understack/releases/download/understack-images-20251016184704/ubuntu-noble.qcow2
45+
is_public: true
46+
is_protected: false
47+
disk_format: qcow2
48+
container_format: bare
49+
min_disk: 0
50+
min_ram: 0
51+
properties:
52+
os_distro: ubuntu
53+
os_version: "24.04"
54+
img_config_drive: mandatory

ansible/roles/openstack_glance_image_upload/tasks/main.yml

Lines changed: 63 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,62 +6,84 @@
66
state: directory
77
mode: '0755'
88

9-
- name: Reserve Glance image IDs before upload
10-
openstack.cloud.image:
9+
- name: Look up existing Glance images
10+
openstack.cloud.image_info:
1111
cloud: "{{ openstack_cloud | default(omit) }}"
12-
name: "{{ item.name }}"
13-
id: "{{ item.uuid }}"
14-
disk_format: "{{ item.disk_format }}"
15-
container_format: "{{ item.container_format | default('bare') }}"
16-
is_public: "{{ item.is_public | default(true) }}"
17-
is_protected: "{{ item.is_protected | default(false) }}"
18-
min_disk: "{{ item.min_disk | default(0) }}"
19-
min_ram: "{{ item.min_ram | default(0) }}"
20-
properties: "{{ item.properties | default({}) }}"
21-
tags: "{{ item.tags | default([]) }}"
22-
state: present
23-
wait: false
12+
image: "{{ item.uuid }}"
13+
register: existing_image_info
2414
loop: "{{ understack_images }}"
2515
loop_control:
2616
label: "{{ item.name }}"
2717
when: understack_images | length > 0
2818

29-
- name: Download images from external URLs
19+
- name: Reserve missing Glance image IDs before upload
20+
openstack.cloud.image:
21+
cloud: "{{ openstack_cloud | default(omit) }}"
22+
name: "{{ item.item.name }}"
23+
id: "{{ item.item.uuid }}"
24+
disk_format: "{{ item.item.disk_format }}"
25+
container_format: "{{ item.item.container_format | default('bare') }}"
26+
is_public: "{{ item.item.is_public | default(true) }}"
27+
is_protected: "{{ item.item.is_protected | default(false) }}"
28+
min_disk: "{{ item.item.min_disk | default(0) }}"
29+
min_ram: "{{ item.item.min_ram | default(0) }}"
30+
properties: "{{ item.item.properties | default({}) }}"
31+
tags: "{{ item.item.tags | default([]) }}"
32+
state: present
33+
wait: false
34+
loop: "{{ existing_image_info.results }}"
35+
loop_control:
36+
label: "{{ item.item.name }}"
37+
when:
38+
- understack_images | length > 0
39+
- item.images | length == 0
40+
41+
- name: Download images that still need data upload
3042
ansible.builtin.get_url:
31-
url: "{{ item.external_url }}"
32-
dest: "{{ image_download_dir }}/{{ item.uuid }}.{{ item.disk_format }}"
33-
checksum: "{{ item.checksum | default(omit) }}"
43+
url: "{{ item.item.external_url }}"
44+
dest: "{{ image_download_dir }}/{{ item.item.uuid }}.{{ item.item.disk_format }}"
45+
checksum: "{{ item.item.checksum | default(omit) }}"
3446
mode: '0644'
47+
loop: "{{ existing_image_info.results }}"
48+
loop_control:
49+
label: "{{ item.item.name }}"
50+
when:
51+
- understack_images | length > 0
52+
- item.images | length == 0 or item.images[0].status == 'queued'
53+
54+
- name: Look up target Glance images after reservation
55+
openstack.cloud.image_info:
56+
cloud: "{{ openstack_cloud | default(omit) }}"
57+
image: "{{ item.uuid }}"
58+
register: target_image_info
3559
loop: "{{ understack_images }}"
3660
loop_control:
3761
label: "{{ item.name }}"
3862
when: understack_images | length > 0
3963

40-
- name: Upload image data to reserved Glance images
64+
- name: Upload image data to queued Glance images
4165
openstack.cloud.image:
4266
cloud: "{{ openstack_cloud | default(omit) }}"
43-
name: "{{ item.name }}"
44-
id: "{{ item.uuid }}"
45-
filename: "{{ image_download_dir }}/{{ item.uuid }}.{{ item.disk_format }}"
46-
disk_format: "{{ item.disk_format }}"
47-
container_format: "{{ item.container_format | default('bare') }}"
48-
is_public: "{{ item.is_public | default(true) }}"
49-
is_protected: "{{ item.is_protected | default(false) }}"
50-
min_disk: "{{ item.min_disk | default(0) }}"
51-
min_ram: "{{ item.min_ram | default(0) }}"
52-
properties: "{{ item.properties | default({}) }}"
53-
tags: "{{ item.tags | default([]) }}"
67+
name: "{{ item.images[0].name }}"
68+
id: "{{ item.item.uuid }}"
69+
filename: "{{ image_download_dir }}/{{ item.item.uuid }}.{{ item.item.disk_format }}"
70+
disk_format: "{{ item.images[0].disk_format }}"
71+
container_format: "{{ item.images[0].container_format }}"
5472
state: present
55-
loop: "{{ understack_images }}"
73+
wait: true
74+
loop: "{{ target_image_info.results }}"
5675
loop_control:
57-
label: "{{ item.name }}"
58-
when: understack_images | length > 0
76+
label: "{{ item.item.name }}"
77+
when:
78+
- understack_images | length > 0
79+
- item.images | length > 0
80+
- item.images[0].status == 'queued'
5981

60-
- name: Clean up downloaded images
61-
ansible.builtin.file:
62-
path: "{{ image_download_dir }}/{{ item.uuid }}.{{ item.disk_format }}"
63-
state: absent
64-
loop: "{{ understack_images }}"
65-
loop_control:
66-
label: "{{ item.name }}"
67-
when: understack_images | length > 0
82+
# - name: Clean up downloaded images
83+
# ansible.builtin.file:
84+
# path: "{{ image_download_dir }}/{{ item.uuid }}.{{ item.disk_format }}"
85+
# state: absent
86+
# loop: "{{ understack_images }}"
87+
# loop_control:
88+
# label: "{{ item.name }}"
89+
# when: understack_images | length > 0

0 commit comments

Comments
 (0)