blob: 461accbad2eba6d063c9ce213a5d11a7c8deb0b3 [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
56 when: _image_format.stdout != glance_image_disk_format
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020057 changed_when: true
Mohammed Naser4b630042023-02-07 20:47:45 +000058 ansible.builtin.command:
59 qemu-img convert -O {{ glance_image_disk_format }} {{ _get_url.dest }} {{ _get_url.dest }}.converted
60
61 - name: Wait until image service ready
62 kubernetes.core.k8s_info:
63 api_version: apps/v1
64 kind: Deployment
65 name: glance-api
66 namespace: openstack
67 wait_sleep: 1
68 wait_timeout: 600
69 wait: true
70 wait_condition:
71 type: Available
72 status: true
73
74 - name: Upload image into Glance
75 openstack.cloud.image:
76 cloud: atmosphere
77 name: "{{ glance_image_name }}"
78 filename: "{{ _get_url.dest }}{% if _image_format.stdout != glance_image_disk_format %}.converted{% endif %}"
79 min_disk: "{{ glance_image_min_disk | default(omit) }}"
80 min_ram: "{{ glance_image_min_ram | default(omit) }}"
81 container_format: "{{ glance_image_container_format | default(omit) }}"
82 disk_format: "{{ glance_image_disk_format | default(omit) }}"
83 properties: "{{ glance_image_properties | default(omit) }}"
84 kernel: "{{ glance_image_kernel | default(omit) }}"
85 ramdisk: "{{ glance_image_ramdisk | default(omit) }}"
86 is_public: "{{ glance_image_is_public | default(omit) }}"
87 tags: "{{ glance_image_tags | default(omit) }}"
88 wait: true
89 timeout: 600
90 # NOTE(mnaser): This often fails since the SSL certificates are not
91 # ready yet. We need to wait for them to be ready.
92 retries: 60
93 delay: 5
94 register: _result
95 until: _result is not failed
96 always:
97 - name: Remove work directory
98 ansible.builtin.file:
99 path: "{{ _workdir.path }}"
100 state: absent