blob: d1c0486701ae99c044fe835601e23e0428fc77a4 [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
21
22- name: Download image and upload into Glance
23 run_once: true
24 when: _image_info.openstack_image == None
25 block:
26 - name: Generate temporary work directory
27 ansible.builtin.tempfile:
28 state: directory
29 register: _workdir
30
31 - name: Download image
32 ansible.builtin.get_url:
33 url: "{{ glance_image_url }}"
34 dest: "{{ _workdir.path }}/{{ glance_image_url | basename }}"
35 mode: 0600
36 register: _get_url
37
38 - name: Get image format
39 changed_when: false
40 ansible.builtin.shell: |
41 set -o pipefail
42 qemu-img info {{ _get_url.dest }} | grep -i "file format" | awk '{ print $3 }'
43 args:
44 executable: /bin/bash
45 register: _image_format
46
47 - name: Convert file to target disk format
48 when: _image_format.stdout != glance_image_disk_format
49 ansible.builtin.command:
50 qemu-img convert -O {{ glance_image_disk_format }} {{ _get_url.dest }} {{ _get_url.dest }}.converted
51
52 - name: Wait until image service ready
53 kubernetes.core.k8s_info:
54 api_version: apps/v1
55 kind: Deployment
56 name: glance-api
57 namespace: openstack
58 wait_sleep: 1
59 wait_timeout: 600
60 wait: true
61 wait_condition:
62 type: Available
63 status: true
64
65 - name: Upload image into Glance
66 openstack.cloud.image:
67 cloud: atmosphere
68 name: "{{ glance_image_name }}"
69 filename: "{{ _get_url.dest }}{% if _image_format.stdout != glance_image_disk_format %}.converted{% endif %}"
70 min_disk: "{{ glance_image_min_disk | default(omit) }}"
71 min_ram: "{{ glance_image_min_ram | default(omit) }}"
72 container_format: "{{ glance_image_container_format | default(omit) }}"
73 disk_format: "{{ glance_image_disk_format | default(omit) }}"
74 properties: "{{ glance_image_properties | default(omit) }}"
75 kernel: "{{ glance_image_kernel | default(omit) }}"
76 ramdisk: "{{ glance_image_ramdisk | default(omit) }}"
77 is_public: "{{ glance_image_is_public | default(omit) }}"
78 tags: "{{ glance_image_tags | default(omit) }}"
79 wait: true
80 timeout: 600
81 # NOTE(mnaser): This often fails since the SSL certificates are not
82 # ready yet. We need to wait for them to be ready.
83 retries: 60
84 delay: 5
85 register: _result
86 until: _result is not failed
87 always:
88 - name: Remove work directory
89 ansible.builtin.file:
90 path: "{{ _workdir.path }}"
91 state: absent