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] }}"
22 image_filename: "{{ release }}-server-cloudimg-{{ YARD_IMG_ARCH }}-{{ boot_mode }}.img"
23 image_path: "{{ release }}/current/{{ image_filename }}"
24 host: "{{ lookup('env', 'HOST')|default('cloud-images.ubuntu.com', true)}}"
25 image_url: "{{ lookup('env', 'IMAGE_URL')|default('https://' ~ host ~ '/' ~ image_path, true) }}"
26 image_dest: "{{ workspace }}/{{ image_filename }}"
27 sha256sums_path: "{{ release }}/current/SHA256SUMS"
28 sha256sums_filename: "{{ sha256sums_path|basename }}"
29 sha256sums_url: "{{ lookup('env', 'SHA256SUMS_URL')|default('https://' ~ host ~ '/' ~ sha256sums_path, true) }}"
31 workspace: "{{ lookup('env', 'workspace')|default('/tmp/workspace/yardstick', true) }}"
32 raw_imgfile_basename: "yardstick-{{ release }}-server.raw"
34 RedHat: cloud-utils-growpart
35 Debian: cloud-guest-utils
37 - PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/bin
44 - package: name=parted state=present
45 - package: name=kpartx state=present
46 - package: name="{{ growpart_package[ansible_os_family] }}" state=present
49 imgfile: "{{ normal_image_file }}"
50 when: img_property == "normal"
53 imgfile: "{{ nsb_image_file }}"
54 when: img_property == "nsb"
57 mountdir: "{{ lookup('env', 'mountdir')|default('/mnt/yardstick', true) }}"
60 raw_imgfile: "{{ workspace }}/{{ raw_imgfile_basename }}"
63 - name: unmount all old mount points
69 - "{{ mountdir }}/proc"
71 - "/mnt/{{ release }}"
73 - name: kpartx -dv to delete all image partition device nodes
74 command: kpartx -dv "{{ raw_imgfile }}"
77 - name: delete {{ raw_imgfile }}
79 path: "{{ raw_imgfile }}"
83 - name: remove {{ mountdir }}
85 path: "{{ mountdir }}"
89 - name: remove {{ workspace }}
91 path: "{{ workspace }}"
94 - name: "fetch {{ image_url }} and verify "
96 url: "{{ image_url }}"
97 sha256url: "{{ sha256sums_url }}"
98 dest: "{{ image_dest }}"
100 - name: convert image to raw
101 command: "qemu-img convert {{ image_dest }} {{ raw_imgfile }}"
103 - name: resize image to allow for more VNFs
104 command: "qemu-img resize -f raw {{ raw_imgfile }} +2G"
106 - name: resize parition to allow for more VNFs
107 # use growpart because maybe it handles GPT better than parted
108 command: growpart {{ raw_imgfile }} 1
110 - name: create mknod devices in chroot
111 command: "mknod -m 0660 /dev/loop{{ item }} b 7 {{ item }}"
113 creates: "/dev/loop{{ item }}"
114 with_sequence: start=0 end=9
117 - name: find first partition device
118 # command: kpartx -l "{{ loop_device }}"
119 command: kpartx -l "{{ raw_imgfile }}"
123 image_first_partition: "{{ kpartx_res.stdout_lines[0].split()[0] }}"
126 # assume / is the first partition
127 image_first_partition_device: "/dev/mapper/{{ image_first_partition }}"
129 - name: use kpartx to create device nodes for the raw image loop device
130 # operate on the loop device to avoid /dev namespace missing devices
131 command: kpartx -avs "{{ raw_imgfile }}"
133 - name: parted dump raw image
134 command: parted "{{ raw_imgfile }}" print
141 - name: use blkid to find filesystem type of first partition device
142 command: blkid -o value -s TYPE {{ image_first_partition_device }}
146 image_fs_type: "{{ blkid_res.stdout.strip() }}"
148 msg: "We only support ext4 image filesystems because we have to resize"
149 when: image_fs_type != "ext4"
151 - name: fsck the image filesystem
152 command: "e2fsck -y -f {{ image_first_partition_device }}"
154 - name: resize filesystem to full partition size
155 command: resize2fs {{ image_first_partition_device }}
157 - name: fsck the image filesystem
158 command: "e2fsck -y -f {{ image_first_partition_device }}"
160 - name: make tmp disposable fstab
161 command: mktemp --tmpdir fake_fstab.XXXXXXXXXX
165 fake_fstab: "{{ mktemp_res.stdout.strip() }}"
167 - name: mount first parition on image device
169 src: "{{ image_first_partition_device }}"
170 name: "{{ mountdir }}"
172 fstype: "{{ image_fs_type }}"
173 # !!!!!!! this is required otherwise we add entries to /etc/fstab
174 # and prevent the system from booting
175 fstab: "{{ fake_fstab }}"
178 - name: mount chroot /proc
181 name: "{{ mountdir }}/proc"
183 # !!!!!!! this is required otherwise we add entries to /etc/fstab
184 # and prevent the system from booting
185 fstab: "{{ fake_fstab }}"
188 - name: if arm copy qemu-aarch64-static into chroot
190 src: /usr/bin/qemu-aarch64-static
191 dest: "{{ mountdir }}/usr/bin"
192 when: 'YARD_IMG_ARCH == "arm64"'
194 - name: create ubuntu policy-rc.d workaround
196 content: "{{ '#!/bin/sh\nexit 101\n' }}"
197 dest: "{{ mountdir }}/usr/sbin/policy-rc.d"
199 when: "target_os == 'Ubuntu'"
201 - name: add chroot as host
203 name: "{{ mountdir }}"
204 groups: chroot_image,image_builder
206 ansible_python_interpreter: /usr/bin/python3
207 # set this host variable here
208 nameserver_ip: "{{ ansible_dns.nameservers[0] }}"
211 - name: include ubuntu_server_cloudimg_modify.yml
212 include: ubuntu_server_cloudimg_modify.yml
213 when: img_property == "normal"
215 - name: include ubuntu_server_cloudimg_modify_samplevnfs.yml
216 include: ubuntu_server_cloudimg_modify_samplevnfs.yml
217 when: img_property == "nsb"
221 - name: convert image to image file
222 command: "qemu-img convert -c -o compat=0.10 -O qcow2 {{ raw_imgfile }} {{ imgfile }}"
224 - name: run post build tasks
225 include: post_build_yardstick_image.yml
231 msg: "yardstick image = {{ imgfile }}"