|
6 | 6 | state: directory |
7 | 7 | mode: '0755' |
8 | 8 |
|
9 | | -- name: Reserve Glance image IDs before upload |
10 | | - openstack.cloud.image: |
| 9 | +- name: Look up existing Glance images |
| 10 | + openstack.cloud.image_info: |
11 | 11 | 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 |
24 | 14 | loop: "{{ understack_images }}" |
25 | 15 | loop_control: |
26 | 16 | label: "{{ item.name }}" |
27 | 17 | when: understack_images | length > 0 |
28 | 18 |
|
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 |
30 | 42 | 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) }}" |
34 | 46 | 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 |
35 | 59 | loop: "{{ understack_images }}" |
36 | 60 | loop_control: |
37 | 61 | label: "{{ item.name }}" |
38 | 62 | when: understack_images | length > 0 |
39 | 63 |
|
40 | | -- name: Upload image data to reserved Glance images |
| 64 | +- name: Upload image data to queued Glance images |
41 | 65 | openstack.cloud.image: |
42 | 66 | 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 }}" |
54 | 72 | state: present |
55 | | - loop: "{{ understack_images }}" |
| 73 | + wait: true |
| 74 | + loop: "{{ target_image_info.results }}" |
56 | 75 | 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' |
59 | 81 |
|
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