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