1 # Copyright (c) 2017 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
21 boot_mode: "{{ boot_modes[YARD_IMG_ARCH] }}"
23 'xenial': "{{ release }}-server-cloudimg-{{ YARD_IMG_ARCH }}-{{ boot_mode }}.img"
24 'bionic': "{{ release }}-server-cloudimg-{{ YARD_IMG_ARCH }}.img"
25 image_path: "{{ release }}/current/{{ image_filename[release] }}"
26 host: "{{ lookup('env', 'HOST')|default('cloud-images.ubuntu.com', true)}}"
27 image_url: "{{ lookup('env', 'IMAGE_URL')|default('https://' ~ host ~ '/' ~ image_path, true) }}"
28 image_dest: "{{ workspace }}/{{ image_filename[release] }}"
29 sha256sums_path: "{{ release }}/current/SHA256SUMS"
30 sha256sums_filename: "{{ sha256sums_path|basename }}"
31 sha256sums_url: "{{ lookup('env', 'SHA256SUMS_URL')|default('https://' ~ host ~ '/' ~ sha256sums_path, true) }}"
33 workspace: "{{ lookup('env', 'workspace')|default('/tmp/workspace/yardstick', true) }}"
34 raw_imgfile_basename: "yardstick-{{ release }}-server.raw"
36 RedHat: cloud-utils-growpart
37 Debian: cloud-guest-utils
39 - PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/bin
46 - package: name=parted state=present
47 - package: name=kpartx state=present
48 - package: name="{{ growpart_package[ansible_os_family] }}" state=present
51 imgfile: "{{ normal_image_file }}"
52 when: img_property == "normal"
55 imgfile: "{{ nsb_image_file }}"
56 when: img_property == "nsb"
59 mountdir: "{{ lookup('env', 'mountdir')|default('/mnt/yardstick', true) }}"
62 raw_imgfile: "{{ workspace }}/{{ raw_imgfile_basename }}"
65 - name: unmount all old mount points
71 - "{{ mountdir }}/proc"
73 - "/mnt/{{ release }}"
75 - name: kpartx -dv to delete all image partition device nodes
76 command: kpartx -dv "{{ raw_imgfile }}"
79 - name: Debug dump loop devices
83 - name: delete loop devices for image file
84 # use this because kpartx -dv will fail if raw_imgfile was delete
85 # but in theory we could have deleted file still attached to loopback device?
86 # use grep because of // and awk
87 shell: losetup -O NAME,BACK-FILE | grep "{{ raw_imgfile_basename }}" | awk '{ print $1 }' | xargs -l1 losetup -v -d
90 - name: Debug dump loop devices again
94 - name: delete {{ raw_imgfile }}
96 path: "{{ raw_imgfile }}"
100 - name: remove {{ mountdir }}
102 path: "{{ mountdir }}"
106 - name: remove {{ workspace }}
108 path: "{{ workspace }}"
111 - name: "fetch {{ image_url }} and verify "
112 fetch_url_and_verify:
113 url: "{{ image_url }}"
114 sha256url: "{{ sha256sums_url }}"
115 dest: "{{ image_dest }}"
117 - name: convert image to raw
118 command: "qemu-img convert {{ image_dest }} {{ raw_imgfile }}"
120 - name: resize image to allow for more VNFs
121 command: "qemu-img resize -f raw {{ raw_imgfile }} +2G"
123 - name: resize parition to allow for more VNFs
124 # use growpart because maybe it handles GPT better than parted
125 command: growpart {{ raw_imgfile }} 1
127 - name: create mknod devices in chroot
128 command: "mknod -m 0660 /dev/loop{{ item }} b 7 {{ item }}"
130 creates: "/dev/loop{{ item }}"
131 with_sequence: start=0 end=9
134 - name: find first partition device
135 command: kpartx -l "{{ raw_imgfile }}"
139 image_first_partition: "{{ kpartx_res.stdout_lines[0].split()[0] }}"
142 # assume / is the first partition
143 image_first_partition_device: "/dev/mapper/{{ image_first_partition }}"
145 - name: use kpartx to create device nodes for the raw image loop device
146 # operate on the loop device to avoid /dev namespace missing devices
147 command: kpartx -avs "{{ raw_imgfile }}"
149 - name: parted dump raw image
150 command: parted "{{ raw_imgfile }}" print
157 - name: use blkid to find filesystem type of first partition device
158 command: blkid -o value -s TYPE {{ image_first_partition_device }}
162 image_fs_type: "{{ blkid_res.stdout.strip() }}"
164 msg: "We only support ext4 image filesystems because we have to resize"
165 when: image_fs_type != "ext4"
167 - name: fsck the image filesystem
168 command: "e2fsck -y -f {{ image_first_partition_device }}"
170 - name: resize filesystem to full partition size
171 command: resize2fs {{ image_first_partition_device }}
173 - name: fsck the image filesystem
174 command: "e2fsck -y -f {{ image_first_partition_device }}"
176 - name: make tmp disposable fstab
177 command: mktemp --tmpdir fake_fstab.XXXXXXXXXX
181 fake_fstab: "{{ mktemp_res.stdout.strip() }}"
183 - name: mount first parition on image device
185 src: "{{ image_first_partition_device }}"
186 name: "{{ mountdir }}"
188 fstype: "{{ image_fs_type }}"
189 # !!!!!!! this is required otherwise we add entries to /etc/fstab
190 # and prevent the system from booting
191 fstab: "{{ fake_fstab }}"
194 - name: mount chroot /proc
197 name: "{{ mountdir }}/proc"
199 # !!!!!!! this is required otherwise we add entries to /etc/fstab
200 # and prevent the system from booting
201 fstab: "{{ fake_fstab }}"
204 - name: if arm copy qemu-aarch64-static into chroot
206 src: /usr/bin/qemu-aarch64-static
207 dest: "{{ mountdir }}/usr/bin"
208 when: 'YARD_IMG_ARCH == "arm64"'
210 - name: create ubuntu policy-rc.d workaround
212 content: "{{ '#!/bin/sh\nexit 101\n' }}"
213 dest: "{{ mountdir }}/usr/sbin/policy-rc.d"
215 when: "target_os == 'Ubuntu'"
217 - name: add chroot as host
219 name: "{{ mountdir }}"
220 groups: chroot_image,image_builder
222 ansible_python_interpreter: /usr/bin/python3
223 # set this host variable here
224 nameserver_ip: "{{ ansible_dns.nameservers[0] }}"
227 - name: include ubuntu_server_cloudimg_modify.yml
228 include: ubuntu_server_cloudimg_modify.yml
229 when: img_property == "normal"
231 - name: include ubuntu_server_cloudimg_modify_samplevnfs.yml
232 include: ubuntu_server_cloudimg_modify_samplevnfs.yml
233 when: img_property == "nsb"
237 - name: convert image to image file
238 command: "qemu-img convert -c -o compat=0.10 -O qcow2 {{ raw_imgfile }} {{ imgfile }}"
240 - name: run post build tasks
241 include: post_build_yardstick_image.yml
247 msg: "yardstick image = {{ imgfile }}"