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 mountdir: "{{ lookup('env', 'mountdir')|default('/mnt/yardstick', true) }}"
32 workspace: "{{ lookup('env', 'workspace')|default('/tmp/workspace/yardstick', true) }}"
33 imgfile: "{{ workspace }}/yardstick-image.img"
34 raw_imgfile_basename: "yardstick-{{ release }}-server.raw"
35 raw_imgfile: "{{ workspace }}/{{ raw_imgfile_basename }}"
37 PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/bin
43 - package: name=parted state=present
46 - name: unmount all old mount points
52 - "{{ mountdir }}/proc"
54 - "/mnt/{{ release }}"
56 - name: kpartx -dv to delete all image partition device nodes
57 command: kpartx -dv "{{ raw_imgfile }}"
60 - name: delete {{ raw_imgfile }}
62 path: "{{ raw_imgfile }}"
66 - name: remove {{ mountdir }}
68 path: "{{ mountdir }}"
73 - name: remove {{ workspace }}
75 path: "{{ workspace }}"
78 - name: "fetch {{ image_url }} and verify "
80 url: "{{ image_url }}"
81 sha256url: "{{ sha256sums_url }}"
82 dest: "{{ image_dest }}"
85 # url: "{{ sha256sums_url }}"
87 # dest: "{{ workspace }}/{{ sha256sums_filename }}"
89 # must use wget to workaround ubuntu cloud SSL certs checking failures
90 # - command: "curl -sS -o {{ workspace }}/{{ sha256sums_filename }} {{ sha256sums_url }}"
93 # - command: cat "{{ workspace }}/{{ sha256sums_filename }}"
94 # register: sha256sum_file
97 # image_sha256: "{{ sha256sum_file.stdout|regex_search('^([a-f0-9]+).*' ~ img ~ '$', '\\1', multiline=True) }}"
100 # url: "{{ image_url }}"
102 # dest: "{{ workspace }}/{{ image_filename }}"
103 # checksum: "sha256:{{ image_sha256 }}"
104 # register: fetch_image_status
107 # until: fetch_image_status|succeeded
109 # - name: "Fetch {{ image_url }}"
110 # - command: "curl -sS -o {{ workspace }}/{{ image_filename }} {{ image_url }}"
111 # register: fetch_image_status
114 # until: fetch_image_status|succeeded
116 # - name: Verify sha256sum of downloaded image
117 # - command: "sha256sum -c --ignore-missing {{ workspace }}/{{ sha256sums_filename }}"
119 # - name: create loop devices
120 # command: "mknod -m 660 /dev/loop{{ item }} b 7 {{ item }}"
122 # creates: "/dev/loop{{ item }}"
128 - name: convert image to raw
129 command: "qemu-img convert {{ image_dest }} {{ raw_imgfile }}"
134 # - shell: echo -e "d\\nn\\np\\n1\\n\\n\\nw" | parted -l "{{ raw_imgfile }}"
136 # device: "{{ raw_imgfile }}"
140 - name: create mknod devices in chroot
141 command: "mknod -m 0660 /dev/loop{{ item }} b 7 {{ item }}"
143 creates: "/dev/loop{{ item }}"
144 with_sequence: start=0 end=9
147 # - command: losetup --show --partscan --find "{{ raw_imgfile }}"
148 # register: loop_device_res
151 # var: loop_device_res
155 # loop_device: "{{ loop_device_res.stdout.strip() }}"
158 # path: "{{ loop_device }}"
162 # - command: dmsetup ls
164 - name: find first partition device
165 # command: kpartx -l "{{ loop_device }}"
166 command: kpartx -l "{{ raw_imgfile }}"
170 image_first_partition: "{{ kpartx_res.stdout_lines[0].split()[0] }}"
173 # assume / is the first partition
174 image_first_partition_device: "/dev/mapper/{{ image_first_partition }}"
176 - name: use kpartx to create device nodes for the raw image loop device
177 # operate on the loop device to avoid /dev namespace missing devices
178 # command: kpartx -avs "{{ loop_device }}"
179 command: kpartx -avs "{{ raw_imgfile }}"
181 - name: parted dump raw image
182 # command: parted "{{ loop_device }}" print
183 command: parted "{{ raw_imgfile }}" print
190 - name: use blkid to find filesystem type of first partition device
191 command: blkid -o value -s TYPE {{ image_first_partition_device }}
195 image_fs_type: "{{ blkid_res.stdout.strip() }}"
197 - name: make tmp disposable fstab
198 command: mktemp fake_fstab.XXXXXXXXXX
202 fake_fstab: "{{ mktemp_res.stdout.strip() }}"
204 - name: mount first parition on image device
206 src: "{{ image_first_partition_device }}"
207 name: "{{ mountdir }}"
209 fstype: "{{ image_fs_type }}"
210 #fstab: "{{ fake_fstab }}"
213 - name: mount chroot /proc
216 name: "{{ mountdir }}/proc"
218 #fstab: "{{ fake_fstab }}"
221 - name: if arm copy qemu-aarch64-static into chroot
223 src: /usr/bin/qemu-aarch64-static
224 dest: "{{ mountdir }}/usr/bin"
225 when: 'YARD_IMG_ARCH == "arm64"'
229 # - file: "path={{ mountdir }} state=directory"
232 # src: "{{ image_filename }}"
233 # dest: "{{ mountdir }}"
240 - name: create ubuntu policy-rc.d workaround
242 content: "{{ '#!/bin/sh\nexit 101\n' }}"
243 dest: "{{ mountdir }}/usr/sbin/policy-rc.d"
245 when: "target_os == 'Ubuntu'"
247 - name: set img_modify_playbook
249 img_modify_playbook: ubuntu_server_cloudimg_modify.yml
252 var: img_modify_playbook
255 - name: add chroot as host
257 name: "{{ mountdir }}"
258 groups: chroot_image,image_builder
260 ansible_python_interpreter: /usr/bin/python3
261 # set this host variable here
262 nameserver_ip: "{{ ansible_dns.nameservers[0] }}"
264 - name: include {{ img_modify_playbook }}
265 include: "{{ img_modify_playbook }}"
267 - name: run post build tasks
268 include: post_build_yardstick_image.yml