-
Notifications
You must be signed in to change notification settings - Fork 48
/
main.yml
211 lines (211 loc) · 8.55 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
# If attempting to utilize a base Ubuntu image, diskimage-builder
# is the recommended, and default path.
- name: "Test if image is present"
stat: path={{ dib_imagename }}
register: test_image_present
- name: "Test if image is present - {{ dib_imagename }}.{{ dib_imagetype | default('qcow2') }}"
stat: path={{ dib_imagename }}.{{ dib_imagetype | default('qcow2') }}
register: test_image_dib_present
when: not test_image_present.stat.exists
# Note(TheJulia): We need to explicitly test for initramfs in the case
# that the ironic-python-agent-ramdisk element is used to build the image.
- name: "Test if image is present - {{ dib_imagename }}.initramfs"
stat: path={{ dib_imagename }}.initramfs
register: test_image_initramfs_present
when:
- not test_image_present.stat.exists
- not test_image_dib_present.stat.exists
- name: "Build tracing (-x) option for disk-image-create"
set_fact:
dib_trace_arg: "-x"
when: dib_trace | bool
- name: "Build uncompressed (-u) option for disk-image-create"
set_fact:
dib_uncompressed_arg: "-u"
when: dib_uncompressed | bool
- name: "Build clear environment (-c) option for disk-image-create"
set_fact:
dib_clearenv_arg: "-c"
when: dib_clearenv | bool
- name: "Build no tmpfs (--no-tmpfs) option for disk-image-create"
set_fact:
dib_notmpfs_arg: "--no-tmpfs"
when: dib_notmpfs | bool
- name: "Build offline (--offline) option for disk-image-create"
set_fact:
dib_offline_arg: "--offline"
when: dib_offline | bool
- name: "Build skip default base element (-n) option for disk-image-create"
set_fact:
dib_skipbase_arg: "-n"
when: dib_skipbase | bool
- name: "Build architecture (-a) option for disk-image-create"
set_fact:
dib_arch_arg: "-a {{ dib_arch }}"
when: dib_arch is defined
- name: "Build image name (-o) option for disk-image-create"
set_fact:
dib_imagename_arg: "-o {{ dib_imagename }}"
when: dib_imagename is defined
- name: "Build image type (-t) option for disk-image-create"
set_fact:
dib_imagetype_arg: "-t {{ dib_imagetype }}"
when: dib_imagetype is defined
- name: "Build image size (--image-size) option for disk-image-create"
set_fact:
dib_imagesize_arg: "--image-size {{ dib_imagesize }}"
when: dib_imagesize is defined
- name: "Build image cache (--image-cache) option for disk-image-create"
set_fact:
dib_imagecache_arg: "--image-cache {{ dib_imagecache }}"
when: dib_imagecache is defined
- name: "Build max online resize (--max-online-resize) option for disk-image-create"
set_fact:
dib_maxresize_arg: "--max-online-resize {{ dib_maxresize }}"
when: dib_maxresize is defined
- name: "Build minimum tmpfs size (--min-tmpfs) option for disk-image-create"
set_fact:
dib_mintmpfs_arg: "--min-tmpfs {{ dib_mintmpfs }}"
when: dib_mintmpfs is defined
- name: "Build mkfs options (--mkfs-options) option for disk-image-create"
set_fact:
dib_mkfsfopts_arg: "-mkfs-options {{ dib_mkfsopts }}"
when: dib_mkfsopts is defined
- name: "Build qemu image options (--qemu-img-options) option for disk-image-create"
set_fact:
dib_qemuopts_arg: "--qemu-img-options {{ dib_qemuopts }}"
when: dib_qemuopts is defined
- name: "Build root label (--root-label) option for disk-image-create"
set_fact:
dib_rootlabel_arg: "--root-label {{ dib_rootlabel }}"
when: dib_rootlabel is defined
- name: "Build ramdisk element (--ramdisk-element) option for disk-image-create"
set_fact:
dib_rdelement_arg: "--ramdisk-element {{ dib_rdelement }}"
when: dib_rdelement is defined
- name: "Build install type (--install-type) option for disk-image-create"
set_fact:
dib_installtype_arg: "-t {{ dib_installtype }}"
when: dib_installtype is defined
- name: "Build packages (-p) option for disk-image-create"
set_fact:
dib_packages_arg: "-p {{ dib_packages }}"
when:
- dib_packages is defined
- dib_packages | length > 0
- name: "Set default of Debian Bullseye if building debian and not explicitly set, override with dib_os_release setting"
set_fact:
dib_os_release: "bullseye"
when: dib_os_element == "debian" and dib_os_release is undefined
- name: "Initialize DIB source-repository variables"
set_fact:
dib_source_repositories:
DIB_REPOLOCATION_ironic_python_agent: "{{ ipa_git_folder }}"
DIB_REPOLOCATION_requirements: "{{ reqs_git_folder }}"
# NOTE(dtantsur): using HEAD to avoid changing whatever is checked out
DIB_REPOREF_ironic_python_agent: HEAD
DIB_REPOREF_requirements: HEAD
- name: "Initialize the DIB environment variables fact"
set_fact:
dib_env_vars_final: "{{ dib_env_vars | combine(dib_source_repositories) }}"
- name: "Set the DIB_RELEASE environment variable if set"
set_fact:
dib_env_vars_final: "{{ dib_env_vars_final | combine({'DIB_RELEASE':dib_os_release}) }}"
when: dib_os_release is defined
- name: "Build ELEMENTS_PATH variable from IPA builder element folder"
set_fact:
dib_elements_path: "{{ [ ipa_builder_git_folder + '/dib' ] }}"
- name: "Add existing ELEMENTS_PATH value if present"
set_fact:
dib_elements_path: "{{ dib_elements_path + [dib_env_vars_final['ELEMENTS_PATH']] }}"
when: "'ELEMENTS_PATH' in dib_env_vars_final"
- name: "Set the ELEMENTS_PATH environment variable"
set_fact:
dib_env_vars_final: "{{ dib_env_vars_final | combine({'ELEMENTS_PATH': dib_elements_path | join(':') }) }}"
- name: "Set the DIB_BLOCK_DEVICE_CONFIG variable if set"
set_fact:
dib_env_vars_final: "{{ dib_env_vars_final | combine({'DIB_BLOCK_DEVICE_CONFIG': dib_partitioning}) }}"
when:
- dib_partitioning is defined
- dib_partitioning | length > 0
- name: "Set partitioning information if set"
slurp:
src: "{{ partitioning_file }}"
register: partition_info
when: partitioning_file is defined
- name: "Set partitioning information string if set"
set_fact:
dib_partitioning: "{{ partition_info['content'] | b64decode }}"
when: partition_info is defined and 'content' in partition_info
- name: "Build argument list"
set_fact:
dib_arglist: >-
{{ dib_trace_arg|default('') }}
{{ dib_uncompressed_arg|default('') }}
{{ dib_clearenv_arg|default('') }}
{{ dib_notmpfs_arg|default('') }}
{{ dib_offline_arg|default('') }}
{{ dib_skipbase_arg|default('') }}
{{ dib_arch_arg|default('') }}
{{ dib_imagename_arg|default('') }}
{{ dib_imagetype_arg|default('') }}
{{ dib_imagesize_arg|default('') }}
{{ dib_imagecache_arg|default('') }}
{{ dib_maxresize_arg|default('') }}
{{ dib_mintmpfs_arg|default('') }}
{{ dib_mkfsopts_arg|default('') }}
{{ dib_qemuopts_arg|default('') }}
{{ dib_rootlabel_arg|default('') }}
{{ dib_rdelement_arg|default('') }}
{{ dib_installtype_arg|default('') }}
{{ dib_packages_arg|default('') }}
{{ dib_os_element }}
{{ dib_elements|default('') }}
- name: "Initiate image build"
shell: |
set -o pipefail
disk-image-create {{ dib_arglist }} 2>&1 | tee {{ disk_image_create_log }}
args:
executable: /bin/bash
environment: "{{ dib_env_vars_final | combine(bifrost_venv_env) }}"
when:
- not build_ramdisk | bool
- not test_image_present.stat.exists
- not test_image_dib_present.stat.exists
- not test_image_initramfs_present.stat.exists
- name: "Initiate ramdisk build"
command: ramdisk-image-create {{ dib_arglist }}
environment: "{{ dib_env_vars_final | combine(bifrost_venv_env) }}"
when:
- build_ramdisk | bool
- not test_image_present.stat.exists
- not test_image_dib_present.stat.exists
- not test_image_initramfs_present.stat.exists
- name: "Update permission of generated image"
file:
path: "{{ http_boot_folder }}"
mode: u=rwX,g=rX,o=rX
recurse: yes
state: directory
when:
- http_boot_folder is defined
- http_boot_folder | length > 0
- name: "Restore proper context on created data for http_boot"
command: restorecon -iRv {{ http_boot_folder }}
when: (ansible_os_family == 'RedHat' or ansible_os_family == 'Suse') and
ansible_selinux.status == 'enabled'