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
42 - package: name=parted state=present
45 - name: unmount all old mount points
51 - "{{ mountdir }}/proc"
53 - "/mnt/{{ release }}"
55 - name: kpartx -dv to delete all image partition device nodes
56 command: kpartx -dv "{{ raw_imgfile }}"
59 - name: delete {{ raw_imgfile }}
61 path: "{{ raw_imgfile }}"
65 - name: remove {{ mountdir }}
67 path: "{{ mountdir }}"
72 - name: remove {{ workspace }}
74 path: "{{ workspace }}"
77 - name: "fetch {{ image_url }} and verify "
79 url: "{{ image_url }}"
80 sha256url: "{{ sha256sums_url }}"
81 dest: "{{ image_dest }}"
84 # url: "{{ sha256sums_url }}"
86 # dest: "{{ workspace }}/{{ sha256sums_filename }}"
88 # must use wget to workaround ubuntu cloud SSL certs checking failures
89 # - command: "curl -sS -o {{ workspace }}/{{ sha256sums_filename }} {{ sha256sums_url }}"
92 # - command: cat "{{ workspace }}/{{ sha256sums_filename }}"
93 # register: sha256sum_file
96 # image_sha256: "{{ sha256sum_file.stdout|regex_search('^([a-f0-9]+).*' ~ img ~ '$', '\\1', multiline=True) }}"
99 # url: "{{ image_url }}"
101 # dest: "{{ workspace }}/{{ image_filename }}"
102 # checksum: "sha256:{{ image_sha256 }}"
103 # register: fetch_image_status
106 # until: fetch_image_status|succeeded
108 # - name: "Fetch {{ image_url }}"
109 # - command: "curl -sS -o {{ workspace }}/{{ image_filename }} {{ image_url }}"
110 # register: fetch_image_status
113 # until: fetch_image_status|succeeded
115 # - name: Verify sha256sum of downloaded image
116 # - command: "sha256sum -c --ignore-missing {{ workspace }}/{{ sha256sums_filename }}"
118 # - name: create loop devices
119 # command: "mknod -m 660 /dev/loop{{ item }} b 7 {{ item }}"
121 # creates: "/dev/loop{{ item }}"
127 - name: convert image to raw
128 command: "qemu-img convert {{ image_dest }} {{ raw_imgfile }}"
133 # - shell: echo -e "d\\nn\\np\\n1\\n\\n\\nw" | parted -l "{{ raw_imgfile }}"
135 # device: "{{ raw_imgfile }}"
139 - name: create mknod devices in chroot
140 command: "mknod -m 0660 /dev/loop{{ item }} b 7 {{ item }}"
142 creates: "/dev/loop{{ item }}"
143 with_sequence: start=0 end=9
146 # - command: losetup --show --partscan --find "{{ raw_imgfile }}"
147 # register: loop_device_res
150 # var: loop_device_res
154 # loop_device: "{{ loop_device_res.stdout.strip() }}"
157 # path: "{{ loop_device }}"
161 # - command: dmsetup ls
163 - name: find first partition device
164 # command: kpartx -l "{{ loop_device }}"
165 command: kpartx -l "{{ raw_imgfile }}"
169 image_first_partition: "{{ kpartx_res.stdout_lines[0].split()[0] }}"
172 # assume / is the first partition
173 image_first_partition_device: "/dev/mapper/{{ image_first_partition }}"
175 - name: use kpartx to create device nodes for the raw image loop device
176 # operate on the loop device to avoid /dev namespace missing devices
177 # command: kpartx -avs "{{ loop_device }}"
178 command: kpartx -avs "{{ raw_imgfile }}"
180 - name: parted dump raw image
181 # command: parted "{{ loop_device }}" print
182 command: parted "{{ raw_imgfile }}" print
189 - name: use blkid to find filesystem type of first partition device
190 command: blkid -o value -s TYPE {{ image_first_partition_device }}
194 image_fs_type: "{{ blkid_res.stdout.strip() }}"
196 - name: make tmp disposable fstab
197 command: mktemp fake_fstab.XXXXXXXXXX
201 fake_fstab: "{{ mktemp_res.stdout.strip() }}"
203 - name: mount first parition on image device
205 src: "{{ image_first_partition_device }}"
206 name: "{{ mountdir }}"
208 fstype: "{{ image_fs_type }}"
209 #fstab: "{{ fake_fstab }}"
212 - name: mount chroot /proc
215 name: "{{ mountdir }}/proc"
217 #fstab: "{{ fake_fstab }}"
220 - name: if arm copy qemu-aarch64-static into chroot
222 src: /usr/bin/qemu-aarch64-static
223 dest: "{{ mountdir }}/usr/bin"
224 when: 'YARD_IMG_ARCH == "arm64"'
228 # - file: "path={{ mountdir }} state=directory"
231 # src: "{{ image_filename }}"
232 # dest: "{{ mountdir }}"
239 - name: create ubuntu policy-rc.d workaround
241 content: "{{ '#!/bin/sh\nexit 101\n' }}"
242 dest: "{{ mountdir }}/usr/sbin/policy-rc.d"
244 when: "target_os == 'Ubuntu'"
246 - name: set img_modify_playbook
248 img_modify_playbook: ubuntu_server_cloudimg_modify.yml
251 var: img_modify_playbook
254 - name: add chroot as host
256 name: "{{ mountdir }}"
257 groups: chroot_image,image_builder
259 ansible_python_interpreter: /usr/bin/python3
260 # set this host variable here
261 nameserver_ip: "{{ ansible_dns.nameservers[0] }}"
263 - name: include {{ img_modify_playbook }}
264 include: "{{ img_modify_playbook }}"
266 - name: run post build tasks
267 include: post_build_yardstick_image.yml