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