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 imgfile: "{{ workspace }}/yardstick-image.img"
33 raw_imgfile_basename: "yardstick-{{ release }}-server.raw"
35 PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/bin
41 - package: name=parted state=present
44 mountdir: "{{ lookup('env', 'mountdir')|default('/mnt/yardstick', true) }}"
47 raw_imgfile: "{{ workspace }}/{{ raw_imgfile_basename }}"
50 - name: unmount all old mount points
56 - "{{ mountdir }}/proc"
58 - "/mnt/{{ release }}"
60 - name: kpartx -dv to delete all image partition device nodes
61 command: kpartx -dv "{{ raw_imgfile }}"
64 - name: delete {{ raw_imgfile }}
66 path: "{{ raw_imgfile }}"
70 - name: remove {{ mountdir }}
72 path: "{{ mountdir }}"
77 - name: remove {{ workspace }}
79 path: "{{ workspace }}"
82 - name: "fetch {{ image_url }} and verify "
84 url: "{{ image_url }}"
85 sha256url: "{{ sha256sums_url }}"
86 dest: "{{ image_dest }}"
89 # url: "{{ sha256sums_url }}"
91 # dest: "{{ workspace }}/{{ sha256sums_filename }}"
93 # must use wget to workaround ubuntu cloud SSL certs checking failures
94 # - command: "curl -sS -o {{ workspace }}/{{ sha256sums_filename }} {{ sha256sums_url }}"
97 # - command: cat "{{ workspace }}/{{ sha256sums_filename }}"
98 # register: sha256sum_file
101 # image_sha256: "{{ sha256sum_file.stdout|regex_search('^([a-f0-9]+).*' ~ img ~ '$', '\\1', multiline=True) }}"
104 # url: "{{ image_url }}"
106 # dest: "{{ workspace }}/{{ image_filename }}"
107 # checksum: "sha256:{{ image_sha256 }}"
108 # register: fetch_image_status
111 # until: fetch_image_status|succeeded
113 # - name: "Fetch {{ image_url }}"
114 # - command: "curl -sS -o {{ workspace }}/{{ image_filename }} {{ image_url }}"
115 # register: fetch_image_status
118 # until: fetch_image_status|succeeded
120 # - name: Verify sha256sum of downloaded image
121 # - command: "sha256sum -c --ignore-missing {{ workspace }}/{{ sha256sums_filename }}"
123 # - name: create loop devices
124 # command: "mknod -m 660 /dev/loop{{ item }} b 7 {{ item }}"
126 # creates: "/dev/loop{{ item }}"
132 - name: convert image to raw
133 command: "qemu-img convert {{ image_dest }} {{ raw_imgfile }}"
138 # - shell: echo -e "d\\nn\\np\\n1\\n\\n\\nw" | parted -l "{{ raw_imgfile }}"
140 # device: "{{ raw_imgfile }}"
144 - name: create mknod devices in chroot
145 command: "mknod -m 0660 /dev/loop{{ item }} b 7 {{ item }}"
147 creates: "/dev/loop{{ item }}"
148 with_sequence: start=0 end=9
151 # - command: losetup --show --partscan --find "{{ raw_imgfile }}"
152 # register: loop_device_res
155 # var: loop_device_res
159 # loop_device: "{{ loop_device_res.stdout.strip() }}"
162 # path: "{{ loop_device }}"
166 # - command: dmsetup ls
168 - name: find first partition device
169 # command: kpartx -l "{{ loop_device }}"
170 command: kpartx -l "{{ raw_imgfile }}"
174 image_first_partition: "{{ kpartx_res.stdout_lines[0].split()[0] }}"
177 # assume / is the first partition
178 image_first_partition_device: "/dev/mapper/{{ image_first_partition }}"
180 - name: use kpartx to create device nodes for the raw image loop device
181 # operate on the loop device to avoid /dev namespace missing devices
182 # command: kpartx -avs "{{ loop_device }}"
183 command: kpartx -avs "{{ raw_imgfile }}"
185 - name: parted dump raw image
186 # command: parted "{{ loop_device }}" print
187 command: parted "{{ raw_imgfile }}" print
194 - name: use blkid to find filesystem type of first partition device
195 command: blkid -o value -s TYPE {{ image_first_partition_device }}
199 image_fs_type: "{{ blkid_res.stdout.strip() }}"
201 - name: make tmp disposable fstab
202 command: mktemp fake_fstab.XXXXXXXXXX
206 fake_fstab: "{{ mktemp_res.stdout.strip() }}"
208 - name: mount first parition on image device
210 src: "{{ image_first_partition_device }}"
211 name: "{{ mountdir }}"
213 fstype: "{{ image_fs_type }}"
214 #fstab: "{{ fake_fstab }}"
217 - name: mount chroot /proc
220 name: "{{ mountdir }}/proc"
222 #fstab: "{{ fake_fstab }}"
225 - name: if arm copy qemu-aarch64-static into chroot
227 src: /usr/bin/qemu-aarch64-static
228 dest: "{{ mountdir }}/usr/bin"
229 when: 'YARD_IMG_ARCH == "arm64"'
233 # - file: "path={{ mountdir }} state=directory"
236 # src: "{{ image_filename }}"
237 # dest: "{{ mountdir }}"
244 - name: create ubuntu policy-rc.d workaround
246 content: "{{ '#!/bin/sh\nexit 101\n' }}"
247 dest: "{{ mountdir }}/usr/sbin/policy-rc.d"
249 when: "target_os == 'Ubuntu'"
251 - name: set img_modify_playbook
253 img_modify_playbook: ubuntu_server_cloudimg_modify.yml
256 var: img_modify_playbook
259 - name: add chroot as host
261 name: "{{ mountdir }}"
262 groups: chroot_image,image_builder
264 ansible_python_interpreter: /usr/bin/python3
265 # set this host variable here
266 nameserver_ip: "{{ ansible_dns.nameservers[0] }}"
269 - name: include {{ img_modify_playbook }}
270 include: "{{ img_modify_playbook }}"
272 - name: run post build tasks
273 include: post_build_yardstick_image.yml
279 msg: "yardstick image = {{ raw_imgfile }}"