blob: 1f0059a7ac4be91e9dd6468afbfb2ebf0b602436 [file] [log] [blame]
Mohammed Naser4b630042023-02-07 20:47:45 +00001# Copyright (c) 2023 VEXXHOST, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15- name: Check if image exists
16 run_once: true
17 openstack.cloud.image_info:
18 cloud: atmosphere
19 image: "{{ glance_image_name }}"
20 register: _image_info
Mohammed Naser41f239c2023-02-18 17:34:21 +000021 # NOTE(mnaser): This often fails since the SSL certificates are not
22 # ready yet. We need to wait for them to be ready.
23 retries: 120
24 delay: 1
25 until: _image_info is not failed
Mohammed Naser4b630042023-02-07 20:47:45 +000026
27- name: Download image and upload into Glance
28 run_once: true
Mohammed Naser8ccabb62025-02-05 13:20:09 -050029 when: _image_info.images | length == 0
Mohammed Naser4b630042023-02-07 20:47:45 +000030 block:
31 - name: Generate temporary work directory
32 ansible.builtin.tempfile:
Mohammed Naserd0c8a592025-02-05 11:40:39 -050033 path: "{{ glance_image_tempfile_path | default(omit) }}"
Mohammed Naser4b630042023-02-07 20:47:45 +000034 state: directory
35 register: _workdir
36
37 - name: Download image
38 ansible.builtin.get_url:
39 url: "{{ glance_image_url }}"
40 dest: "{{ _workdir.path }}/{{ glance_image_url | basename }}"
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020041 mode: "0600"
Mohammed Naserd0c8a592025-02-05 11:40:39 -050042 tmp_dest: "{{ _workdir.path }}"
Mohammed Naser4b630042023-02-07 20:47:45 +000043 register: _get_url
Mohammed Naser27971162024-04-03 21:48:17 -040044 retries: 3
45 delay: "{{ 15 | random + 3 }}"
46 until: _get_url is not failed
Guilherme Steinmüllerb835cc22024-07-07 21:10:25 -030047 environment:
48 http_proxy: "{{ glance_image_http_proxy }}"
49 https_proxy: "{{ glance_image_https_proxy }}"
50 no_proxy: "{{ glance_image_no_proxy }}"
Mohammed Naser4b630042023-02-07 20:47:45 +000051
52 - name: Get image format
53 changed_when: false
54 ansible.builtin.shell: |
55 set -o pipefail
56 qemu-img info {{ _get_url.dest }} | grep -i "file format" | awk '{ print $3 }'
57 args:
58 executable: /bin/bash
59 register: _image_format
60
61 - name: Convert file to target disk format
Mohammed Naser306d1e42024-06-17 11:19:49 -040062 when:
63 - glance_image_disk_format not in ['aki', 'ari']
64 - glance_image_disk_format != _image_format.stdout
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020065 changed_when: true
Mohammed Naser4b630042023-02-07 20:47:45 +000066 ansible.builtin.command:
67 qemu-img convert -O {{ glance_image_disk_format }} {{ _get_url.dest }} {{ _get_url.dest }}.converted
Mohammed Naser306d1e42024-06-17 11:19:49 -040068 register: glance_image_conversion
Mohammed Naser4b630042023-02-07 20:47:45 +000069
70 - name: Wait until image service ready
71 kubernetes.core.k8s_info:
72 api_version: apps/v1
73 kind: Deployment
74 name: glance-api
75 namespace: openstack
76 wait_sleep: 1
77 wait_timeout: 600
78 wait: true
79 wait_condition:
80 type: Available
81 status: true
82
83 - name: Upload image into Glance
84 openstack.cloud.image:
85 cloud: atmosphere
86 name: "{{ glance_image_name }}"
Mohammed Naser306d1e42024-06-17 11:19:49 -040087 filename: "{{ _get_url.dest }}{% if glance_image_conversion is not skipped %}.converted{% endif %}"
Mohammed Naser4b630042023-02-07 20:47:45 +000088 min_disk: "{{ glance_image_min_disk | default(omit) }}"
89 min_ram: "{{ glance_image_min_ram | default(omit) }}"
90 container_format: "{{ glance_image_container_format | default(omit) }}"
91 disk_format: "{{ glance_image_disk_format | default(omit) }}"
92 properties: "{{ glance_image_properties | default(omit) }}"
93 kernel: "{{ glance_image_kernel | default(omit) }}"
94 ramdisk: "{{ glance_image_ramdisk | default(omit) }}"
95 is_public: "{{ glance_image_is_public | default(omit) }}"
96 tags: "{{ glance_image_tags | default(omit) }}"
97 wait: true
98 timeout: 600
99 # NOTE(mnaser): This often fails since the SSL certificates are not
100 # ready yet. We need to wait for them to be ready.
Mohammed Naser306d1e42024-06-17 11:19:49 -0400101 retries: "{{ glance_image_retries | default(60) }}"
Mohammed Naser4b630042023-02-07 20:47:45 +0000102 delay: 5
103 register: _result
104 until: _result is not failed
105 always:
106 - name: Remove work directory
107 ansible.builtin.file:
108 path: "{{ _workdir.path }}"
109 state: absent