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 }}"
76 - name: remove {{ workspace }}
78 path: "{{ workspace }}"
81 - name: "fetch {{ image_url }} and verify "
83 url: "{{ image_url }}"
84 sha256url: "{{ sha256sums_url }}"
85 dest: "{{ image_dest }}"
87 - name: convert image to raw
88 command: "qemu-img convert {{ image_dest }} {{ raw_imgfile }}"
90 - name: create mknod devices in chroot
91 command: "mknod -m 0660 /dev/loop{{ item }} b 7 {{ item }}"
93 creates: "/dev/loop{{ item }}"
94 with_sequence: start=0 end=9
97 - name: find first partition device
98 # command: kpartx -l "{{ loop_device }}"
99 command: kpartx -l "{{ raw_imgfile }}"
103 image_first_partition: "{{ kpartx_res.stdout_lines[0].split()[0] }}"
106 # assume / is the first partition
107 image_first_partition_device: "/dev/mapper/{{ image_first_partition }}"
109 - name: use kpartx to create device nodes for the raw image loop device
110 # operate on the loop device to avoid /dev namespace missing devices
111 command: kpartx -avs "{{ raw_imgfile }}"
113 - name: parted dump raw image
114 command: parted "{{ raw_imgfile }}" print
121 - name: use blkid to find filesystem type of first partition device
122 command: blkid -o value -s TYPE {{ image_first_partition_device }}
126 image_fs_type: "{{ blkid_res.stdout.strip() }}"
128 - name: make tmp disposable fstab
129 command: mktemp --tmpdir fake_fstab.XXXXXXXXXX
133 fake_fstab: "{{ mktemp_res.stdout.strip() }}"
135 - name: mount first parition on image device
137 src: "{{ image_first_partition_device }}"
138 name: "{{ mountdir }}"
140 fstype: "{{ image_fs_type }}"
141 # !!!!!!! this is required otherwise we add entries to /etc/fstab
142 # and prevent the system from booting
143 fstab: "{{ fake_fstab }}"
146 - name: mount chroot /proc
149 name: "{{ mountdir }}/proc"
151 # !!!!!!! this is required otherwise we add entries to /etc/fstab
152 # and prevent the system from booting
153 fstab: "{{ fake_fstab }}"
156 - name: if arm copy qemu-aarch64-static into chroot
158 src: /usr/bin/qemu-aarch64-static
159 dest: "{{ mountdir }}/usr/bin"
160 when: 'YARD_IMG_ARCH == "arm64"'
162 - name: create ubuntu policy-rc.d workaround
164 content: "{{ '#!/bin/sh\nexit 101\n' }}"
165 dest: "{{ mountdir }}/usr/sbin/policy-rc.d"
167 when: "target_os == 'Ubuntu'"
169 - name: set img_modify_playbook
171 img_modify_playbook: ubuntu_server_cloudimg_modify.yml
174 var: img_modify_playbook
177 - name: add chroot as host
179 name: "{{ mountdir }}"
180 groups: chroot_image,image_builder
182 ansible_python_interpreter: /usr/bin/python3
183 # set this host variable here
184 nameserver_ip: "{{ ansible_dns.nameservers[0] }}"
187 - name: include {{ img_modify_playbook }}
188 include: "{{ img_modify_playbook }}"
190 - name: run post build tasks
191 include: post_build_yardstick_image.yml
197 msg: "yardstick image = {{ raw_imgfile }}"