|
4 | 4 | msg: os_images_name_suffix is empty please provide it.
|
5 | 5 | when: os_images_name_suffix is defined and os_images_name_suffix | length == 0
|
6 | 6 |
|
7 |
| -- name: Gather retire candidates info |
| 7 | +- name: Gather candidates info |
8 | 8 | openstack.cloud.image_info:
|
9 | 9 | auth_type: "{{ os_images_auth_type }}"
|
10 | 10 | auth: "{{ os_images_auth }}"
|
11 | 11 | cacert: "{{ os_images_cacert | default(omit) }}"
|
12 | 12 | interface: "{{ os_images_interface | default(omit, true) }}"
|
13 | 13 | region_name: "{{ os_images_region | default(omit) }}"
|
14 |
| - register: retire_list |
15 |
| - when: item.rename_image | default(os_images_promote) | bool |
| 14 | + register: retire_or_promote_list |
| 15 | + when: > |
| 16 | + (os_images_list | selectattr('rename_image', 'defined') | list | length > 0) |
| 17 | + or (os_images_promote | bool) |
| 18 | + or (os_images_retire | bool) |
16 | 19 |
|
17 | 20 | - name: Ensure images for retirement exist
|
18 | 21 | ansible.builtin.assert:
|
19 | 22 | that:
|
20 |
| - - item.name in retire_list.openstack_images | map(attribute='name') | list |
| 23 | + - promotion_name in retire_or_promote_list.images | map(attribute='name') | list |
21 | 24 | fail_msg: "The image {{ item.name[: -(os_images_name_suffix | length | int)] }} does not exist."
|
| 25 | + vars: |
| 26 | + promotion_name: "{{ item.name[: -(os_images_name_suffix | length | int)] }}" |
22 | 27 | loop: "{{ os_images_list | list }}"
|
23 |
| - when: item.rename_image | default(os_images_promote) | bool |
24 |
| - |
25 |
| -- name: Gather promote candidates info |
26 |
| - openstack.cloud.image_info: |
27 |
| - auth_type: "{{ os_images_auth_type }}" |
28 |
| - auth: "{{ os_images_auth }}" |
29 |
| - cacert: "{{ os_images_cacert | default(omit) }}" |
30 |
| - interface: "{{ os_images_interface | default(omit, true) }}" |
31 |
| - region_name: "{{ os_images_region | default(omit) }}" |
32 |
| - register: promote_list |
33 |
| - when: item.rename_image | default(os_images_promote) | bool |
| 28 | + when: item.rename_image | default(os_images_retire) | bool |
34 | 29 |
|
35 | 30 | - name: Ensure images for promotion exist
|
36 | 31 | ansible.builtin.assert:
|
37 | 32 | that:
|
38 |
| - - item.name in promote_list.images | map(attribute='name') | list |
| 33 | + - item.name in retire_or_promote_list.images | map(attribute='name') | list |
39 | 34 | fail_msg: The image {{ item.name }} does not exist.
|
40 | 35 | loop: "{{ os_images_list | list }}"
|
41 | 36 | when: item.rename_image | default(os_images_promote) | bool
|
42 | 37 |
|
| 38 | +- name: Check if image suffix is provided |
| 39 | + ansible.builtin.set_fact: |
| 40 | + image_suffix_provided: "{{ os_images_name_suffix is defined and os_images_name_suffix is not none and (os_images_name_suffix | length > 0) }}" |
| 41 | + |
| 42 | +- name: Display info |
| 43 | + ansible.builtin.debug: |
| 44 | + msg: | |
| 45 | + Warning: no image suffix is provided so retired images are not renamed and candidate images are not promoted. |
| 46 | + Images with the `hide_image` attribute will still be hidden. |
| 47 | + when: not (image_suffix_provided | bool) |
| 48 | + |
43 | 49 | - name: Hide retire candidate images
|
44 | 50 | ansible.builtin.command: "{{ os_images_venv }}/bin/openstack image set --hidden {{ promotion_name }}"
|
45 | 51 | vars:
|
46 |
| - promotion_name: "{{ item.name[: -(os_images_name_suffix | length | int)] }}" |
| 52 | + promotion_name: "{{ item.name[: -(os_images_name_suffix | length | int)] if image_suffix_provided else item.name }}" |
47 | 53 | with_items: "{{ os_images_list | list }}"
|
48 | 54 | changed_when: true
|
49 |
| - when: (item.rename_image | default(os_images_promote) | bool) and (item.hide_image | default(os_images_hide) | bool) |
| 55 | + when: (item.hide_image | default(os_images_hide) | bool) |
50 | 56 |
|
51 | 57 | - name: Ensure old images are retired
|
52 | 58 | ansible.builtin.command: "{{ os_images_venv }}/bin/openstack image set {{ promotion_name }} --name {{ promotion_name }}.{{ date_suffix }}"
|
53 | 59 | vars:
|
54 | 60 | date_suffix: "{{ ansible_date_time.date }}"
|
55 | 61 | promotion_name: "{{ item.name[: -(os_images_name_suffix | length | int)] }}"
|
56 | 62 | loop: "{{ os_images_list | list }}"
|
57 |
| - when: item.rename_image | default(os_images_promote) | bool |
58 | 63 | changed_when: true
|
| 64 | + when: image_suffix_provided and (item.rename_image | default(os_images_retire) | bool) |
59 | 65 | environment: "{{ os_images_venv }}"
|
60 | 66 |
|
61 | 67 | - name: Ensure new images are promoted
|
|
64 | 70 | promotion_name: "{{ item.name[: -(os_images_name_suffix | length | int)] }}"
|
65 | 71 | loop: "{{ os_images_list | list }}"
|
66 | 72 | changed_when: true
|
67 |
| - when: item.rename_image | default(os_images_promote) | bool |
| 73 | + when: image_suffix_provided and (item.rename_image | default(os_images_promote) | bool) |
68 | 74 | environment: "{{ os_images_venv }}"
|
| 75 | + |
| 76 | +- name: Discover retired images |
| 77 | + ansible.builtin.set_fact: |
| 78 | + retire_message: | |
| 79 | + The following images have been retired: |
| 80 | + {% for item in images %} |
| 81 | + {{ item.name[: -(os_images_name_suffix | length | int)] }} > {{ item.name[: -(os_images_name_suffix | length | int)] }}.{{ ansible_date_time.date }} |
| 82 | + {% endfor %} |
| 83 | + vars: |
| 84 | + images: "{{ os_images_list | list }}" |
| 85 | + when: image_suffix_provided and (item.rename_image | default(os_images_retire) | bool) |
| 86 | + |
| 87 | +- name: Display info |
| 88 | + ansible.builtin.debug: |
| 89 | + var: retire_message |
| 90 | + when: image_suffix_provided and (item.rename_image | default(os_images_retire) | bool) |
| 91 | + |
| 92 | +- name: Discover promoted images |
| 93 | + ansible.builtin.set_fact: |
| 94 | + promote_message: | |
| 95 | + The following images have been promoted: |
| 96 | + {% for item in images %} |
| 97 | + {{ item.name }} > {{ item.name[: -(os_images_name_suffix | length | int)] }} |
| 98 | + {% endfor %} |
| 99 | + vars: |
| 100 | + images: "{{ os_images_list | list }}" |
| 101 | + when: image_suffix_provided and (item.rename_image | default(os_images_promote) | bool) |
| 102 | + |
| 103 | +- name: Display info |
| 104 | + ansible.builtin.debug: |
| 105 | + var: promote_message |
| 106 | + when: image_suffix_provided and (item.rename_image | default(os_images_promote) | bool) |
0 commit comments