1 # Copyright (c) 2018 Intel Corporation.
\r
3 # Licensed under the Apache License, Version 2.0 (the "License");
\r
4 # you may not use this file except in compliance with the License.
\r
5 # You may obtain a copy of the License at
\r
7 # http://www.apache.org/licenses/LICENSE-2.0
\r
9 # Unless required by applicable law or agreed to in writing, software
\r
10 # distributed under the License is distributed on an "AS IS" BASIS,
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 # See the License for the specific language governing permissions and
\r
13 # limitations under the License.
\r
19 - package: name=parted state=present
\r
20 environment: "{{ proxy_env }}"
\r
22 - package: name=kpartx state=present
\r
23 environment: "{{ proxy_env }}"
\r
25 - package: name="{{ growpart_package[ansible_os_family] }}" state=present
\r
26 environment: "{{ proxy_env }}"
\r
29 imgfile: "{{ normal_image_file }}"
\r
30 when: img_prop_item == "normal"
\r
33 imgfile: "{{ nsb_image_file }}"
\r
34 when: img_prop_item == "nsb"
\r
37 mountdir: "{{ lookup('env', 'mountdir')|default('/mnt/yardstick', true) }}"
\r
38 raw_imgfile: "{{ workspace }}/{{ raw_imgfile_basename }}"
\r
41 - name: unmount all old mount points
\r
47 - "{{ mountdir }}/proc"
\r
48 - "{{ mountdir }}/run"
\r
50 - "/mnt/{{ release }}"
\r
52 - name: kpartx -dv to delete all image partition device nodes
\r
53 command: kpartx -dv "{{ raw_imgfile }}"
\r
56 - name: Debug dump loop devices
\r
60 - name: delete loop devices for image file
\r
61 # use this because kpartx -dv will fail if raw_imgfile was delete
\r
62 # but in theory we could have deleted file still attached to loopback device?
\r
63 # use grep because of // and awk
\r
64 shell: losetup -O NAME,BACK-FILE | grep "{{ raw_imgfile_basename }}" | awk '{ print $1 }' | xargs -l1 losetup -v -d
\r
67 - name: Debug dump loop devices again
\r
71 - name: delete {{ raw_imgfile }}
\r
73 path: "{{ raw_imgfile }}"
\r
77 - name: remove {{ mountdir }}
\r
79 path: "{{ mountdir }}"
\r
83 - name: remove {{ workspace }}
\r
85 path: "{{ workspace }}"
\r
88 - name: "fetch {{ image_url }} and verify "
\r
89 fetch_url_and_verify:
\r
90 url: "{{ image_url }}"
\r
91 sha256url: "{{ sha256sums_url }}"
\r
92 dest: "{{ image_dest }}"
\r
94 - name: convert image to raw
\r
95 command: "qemu-img convert {{ image_dest }} {{ raw_imgfile }}"
\r
97 - name: resize image to allow for more VNFs
\r
98 command: "qemu-img resize -f raw {{ raw_imgfile }} +2G"
\r
100 - name: resize parition to allow for more VNFs
\r
101 # use growpart because maybe it handles GPT better than parted
\r
102 command: growpart {{ raw_imgfile }} 1
\r
104 - name: create mknod devices in chroot
\r
105 command: "mknod -m 0660 /dev/loop{{ item }} b 7 {{ item }}"
\r
107 creates: "/dev/loop{{ item }}"
\r
108 with_sequence: start=0 end=9
\r
109 tags: mknod_devices
\r
111 - name: find first partition device
\r
112 command: kpartx -l "{{ raw_imgfile }}"
\r
113 register: kpartx_res
\r
116 image_first_partition: "{{ kpartx_res.stdout_lines[0].split()[0] }}"
\r
119 # assume / is the first partition
\r
120 image_first_partition_device: "/dev/mapper/{{ image_first_partition }}"
\r
122 - name: use kpartx to create device nodes for the raw image loop device
\r
123 # operate on the loop device to avoid /dev namespace missing devices
\r
124 command: kpartx -avs "{{ raw_imgfile }}"
\r
126 - name: parted dump raw image
\r
127 command: parted "{{ raw_imgfile }}" print
\r
128 register: parted_res
\r
134 - name: use blkid to find filesystem type of first partition device
\r
135 command: blkid -o value -s TYPE {{ image_first_partition_device }}
\r
136 register: blkid_res
\r
139 image_fs_type: "{{ blkid_res.stdout.strip() }}"
\r
142 msg: "We only support ext4 image filesystems because we have to resize"
\r
143 when: image_fs_type != "ext4"
\r
145 - name: fsck the image filesystem
\r
146 command: "e2fsck -y -f {{ image_first_partition_device }}"
\r
148 - name: resize filesystem to full partition size
\r
149 command: resize2fs {{ image_first_partition_device }}
\r
151 - name: fsck the image filesystem
\r
152 command: "e2fsck -y -f {{ image_first_partition_device }}"
\r
154 - name: make tmp disposable fstab
\r
155 command: mktemp --tmpdir fake_fstab.XXXXXXXXXX
\r
156 register: mktemp_res
\r
159 fake_fstab: "{{ mktemp_res.stdout.strip() }}"
\r
161 - name: mount first parition on image device
\r
163 src: "{{ image_first_partition_device }}"
\r
164 name: "{{ mountdir }}"
\r
165 # fstype is required
\r
166 fstype: "{{ image_fs_type }}"
\r
167 # !!!!!!! this is required otherwise we add entries to /etc/fstab
\r
168 # and prevent the system from booting
\r
169 fstab: "{{ fake_fstab }}"
\r
172 - name: mount chroot /proc
\r
175 name: "{{ mountdir }}/proc"
\r
177 # !!!!!!! this is required otherwise we add entries to /etc/fstab
\r
178 # and prevent the system from booting
\r
179 fstab: "{{ fake_fstab }}"
\r
182 - name: mount chroot /run
\r
185 name: "{{ mountdir }}/run"
\r
188 # !!!!!!! this is required otherwise we add entries to /etc/fstab
\r
189 # and prevent the system from booting
\r
190 fstab: "{{ fake_fstab }}"
\r
193 - name: if arm copy qemu-aarch64-static into chroot
\r
195 src: /usr/bin/qemu-aarch64-static
\r
196 dest: "{{ mountdir }}/usr/bin"
\r
197 when: img_arch == arch_arm64
\r
199 - name: create ubuntu policy-rc.d workaround
\r
201 content: "{{ '#!/bin/sh\nexit 101\n' }}"
\r
202 dest: "{{ mountdir }}/usr/sbin/policy-rc.d"
\r
204 when: "target_os == 'Ubuntu'"
\r
206 - name: add chroot as host
\r
208 name: "{{ mountdir }}"
\r
209 groups: chroot_image,image_builder
\r
211 ansible_python_interpreter: /usr/bin/python3
\r
212 # set this host variable here
\r
213 nameserver_ip: "{{ ansible_dns.nameservers[0] }}"
\r