blob: d71439b1111445699a24498837b3870f51c7117a [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
29 when: _image_info.openstack_image == None
30 block:
31 - name: Generate temporary work directory
32 ansible.builtin.tempfile:
33 state: directory
34 register: _workdir
35
36 - name: Download image
37 ansible.builtin.get_url:
38 url: "{{ glance_image_url }}"
39 dest: "{{ _workdir.path }}/{{ glance_image_url | basename }}"
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020040 mode: "0600"
Mohammed Naser4b630042023-02-07 20:47:45 +000041 register: _get_url
Mohammed Naser27971162024-04-03 21:48:17 -040042 retries: 3
43 delay: "{{ 15 | random + 3 }}"
44 until: _get_url is not failed
Mohammed Naser4b630042023-02-07 20:47:45 +000045
46 - name: Get image format
47 changed_when: false
48 ansible.builtin.shell: |
49 set -o pipefail
50 qemu-img info {{ _get_url.dest }} | grep -i "file format" | awk '{ print $3 }'
51 args:
52 executable: /bin/bash
53 register: _image_format
54
55 - name: Convert file to target disk format
vexxhost-bot72490692024-06-17 20:41:58 +020056 when:
57 - glance_image_disk_format not in ['aki', 'ari']
58 - glance_image_disk_format != _image_format.stdout
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020059 changed_when: true
Mohammed Naser4b630042023-02-07 20:47:45 +000060 ansible.builtin.command:
61 qemu-img convert -O {{ glance_image_disk_format }} {{ _get_url.dest }} {{ _get_url.dest }}.converted
vexxhost-bot72490692024-06-17 20:41:58 +020062 register: glance_image_conversion
Mohammed Naser4b630042023-02-07 20:47:45 +000063
64 - name: Wait until image service ready
65 kubernetes.core.k8s_info:
66 api_version: apps/v1
67 kind: Deployment
68 name: glance-api
69 namespace: openstack
70 wait_sleep: 1
71 wait_timeout: 600
72 wait: true
73 wait_condition:
74 type: Available
75 status: true
76
77 - name: Upload image into Glance
78 openstack.cloud.image:
79 cloud: atmosphere
80 name: "{{ glance_image_name }}"
vexxhost-bot72490692024-06-17 20:41:58 +020081 filename: "{{ _get_url.dest }}{% if glance_image_conversion is not skipped %}.converted{% endif %}"
Mohammed Naser4b630042023-02-07 20:47:45 +000082 min_disk: "{{ glance_image_min_disk | default(omit) }}"
83 min_ram: "{{ glance_image_min_ram | default(omit) }}"
84 container_format: "{{ glance_image_container_format | default(omit) }}"
85 disk_format: "{{ glance_image_disk_format | default(omit) }}"
86 properties: "{{ glance_image_properties | default(omit) }}"
87 kernel: "{{ glance_image_kernel | default(omit) }}"
88 ramdisk: "{{ glance_image_ramdisk | default(omit) }}"
89 is_public: "{{ glance_image_is_public | default(omit) }}"
90 tags: "{{ glance_image_tags | default(omit) }}"
91 wait: true
92 timeout: 600
93 # NOTE(mnaser): This often fails since the SSL certificates are not
94 # ready yet. We need to wait for them to be ready.
vexxhost-bot72490692024-06-17 20:41:58 +020095 retries: "{{ glance_image_retries | default(60) }}"
Mohammed Naser4b630042023-02-07 20:47:45 +000096 delay: 5
97 register: _result
98 until: _result is not failed
99 always:
100 - name: Remove work directory
101 ansible.builtin.file:
102 path: "{{ _workdir.path }}"
103 state: absent