blob: 5f56e552e110d62ab5c3ef6e2433a098cfbe719e [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
vexxhost-bot592fae72024-07-08 15:29:59 +020045 environment:
46 http_proxy: "{{ glance_image_http_proxy }}"
47 https_proxy: "{{ glance_image_https_proxy }}"
48 no_proxy: "{{ glance_image_no_proxy }}"
Mohammed Naser4b630042023-02-07 20:47:45 +000049
50 - name: Get image format
51 changed_when: false
52 ansible.builtin.shell: |
53 set -o pipefail
54 qemu-img info {{ _get_url.dest }} | grep -i "file format" | awk '{ print $3 }'
55 args:
56 executable: /bin/bash
57 register: _image_format
58
59 - name: Convert file to target disk format
vexxhost-bot9e933ba2024-06-17 20:39:39 +020060 when:
61 - glance_image_disk_format not in ['aki', 'ari']
62 - glance_image_disk_format != _image_format.stdout
Tadas Sutkaitis4ace4182023-02-27 04:31:52 +020063 changed_when: true
Mohammed Naser4b630042023-02-07 20:47:45 +000064 ansible.builtin.command:
65 qemu-img convert -O {{ glance_image_disk_format }} {{ _get_url.dest }} {{ _get_url.dest }}.converted
vexxhost-bot9e933ba2024-06-17 20:39:39 +020066 register: glance_image_conversion
Mohammed Naser4b630042023-02-07 20:47:45 +000067
68 - name: Wait until image service ready
69 kubernetes.core.k8s_info:
70 api_version: apps/v1
71 kind: Deployment
72 name: glance-api
73 namespace: openstack
74 wait_sleep: 1
75 wait_timeout: 600
76 wait: true
77 wait_condition:
78 type: Available
79 status: true
80
81 - name: Upload image into Glance
82 openstack.cloud.image:
83 cloud: atmosphere
84 name: "{{ glance_image_name }}"
vexxhost-bot9e933ba2024-06-17 20:39:39 +020085 filename: "{{ _get_url.dest }}{% if glance_image_conversion is not skipped %}.converted{% endif %}"
Mohammed Naser4b630042023-02-07 20:47:45 +000086 min_disk: "{{ glance_image_min_disk | default(omit) }}"
87 min_ram: "{{ glance_image_min_ram | default(omit) }}"
88 container_format: "{{ glance_image_container_format | default(omit) }}"
89 disk_format: "{{ glance_image_disk_format | default(omit) }}"
90 properties: "{{ glance_image_properties | default(omit) }}"
91 kernel: "{{ glance_image_kernel | default(omit) }}"
92 ramdisk: "{{ glance_image_ramdisk | default(omit) }}"
93 is_public: "{{ glance_image_is_public | default(omit) }}"
94 tags: "{{ glance_image_tags | default(omit) }}"
95 wait: true
96 timeout: 600
97 # NOTE(mnaser): This often fails since the SSL certificates are not
98 # ready yet. We need to wait for them to be ready.
vexxhost-bot9e933ba2024-06-17 20:39:39 +020099 retries: "{{ glance_image_retries | default(60) }}"
Mohammed Naser4b630042023-02-07 20:47:45 +0000100 delay: 5
101 register: _result
102 until: _result is not failed
103 always:
104 - name: Remove work directory
105 ansible.builtin.file:
106 path: "{{ _workdir.path }}"
107 state: absent