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
49 - "/mnt/{{ release }}"
\r
51 - name: kpartx -dv to delete all image partition device nodes
\r
52 command: kpartx -dv "{{ raw_imgfile }}"
\r
55 - name: Debug dump loop devices
\r
59 - name: delete loop devices for image file
\r
60 # use this because kpartx -dv will fail if raw_imgfile was delete
\r
61 # but in theory we could have deleted file still attached to loopback device?
\r
62 # use grep because of // and awk
\r
63 shell: losetup -O NAME,BACK-FILE | grep "{{ raw_imgfile_basename }}" | awk '{ print $1 }' | xargs -l1 losetup -v -d
\r
66 - name: Debug dump loop devices again
\r
70 - name: delete {{ raw_imgfile }}
\r
72 path: "{{ raw_imgfile }}"
\r
76 - name: remove {{ mountdir }}
\r
78 path: "{{ mountdir }}"
\r
82 - name: remove {{ workspace }}
\r
84 path: "{{ workspace }}"
\r
87 - name: "fetch {{ image_url }} and verify "
\r
88 fetch_url_and_verify:
\r
89 url: "{{ image_url }}"
\r
90 sha256url: "{{ sha256sums_url }}"
\r
91 dest: "{{ image_dest }}"
\r
93 - name: convert image to raw
\r
94 command: "qemu-img convert {{ image_dest }} {{ raw_imgfile }}"
\r
96 - name: resize image to allow for more VNFs
\r
97 command: "qemu-img resize -f raw {{ raw_imgfile }} +2G"
\r
99 - name: resize parition to allow for more VNFs
\r
100 # use growpart because maybe it handles GPT better than parted
\r
101 command: growpart {{ raw_imgfile }} 1
\r
103 - name: create mknod devices in chroot
\r
104 command: "mknod -m 0660 /dev/loop{{ item }} b 7 {{ item }}"
\r
106 creates: "/dev/loop{{ item }}"
\r
107 with_sequence: start=0 end=9
\r
108 tags: mknod_devices
\r
110 - name: find first partition device
\r
111 command: kpartx -l "{{ raw_imgfile }}"
\r
112 register: kpartx_res
\r
115 image_first_partition: "{{ kpartx_res.stdout_lines[0].split()[0] }}"
\r
118 # assume / is the first partition
\r
119 image_first_partition_device: "/dev/mapper/{{ image_first_partition }}"
\r
121 - name: use kpartx to create device nodes for the raw image loop device
\r
122 # operate on the loop device to avoid /dev namespace missing devices
\r
123 command: kpartx -avs "{{ raw_imgfile }}"
\r
125 - name: parted dump raw image
\r
126 command: parted "{{ raw_imgfile }}" print
\r
127 register: parted_res
\r
133 - name: use blkid to find filesystem type of first partition device
\r
134 command: blkid -o value -s TYPE {{ image_first_partition_device }}
\r
135 register: blkid_res
\r
138 image_fs_type: "{{ blkid_res.stdout.strip() }}"
\r
141 msg: "We only support ext4 image filesystems because we have to resize"
\r
142 when: image_fs_type != "ext4"
\r
144 - name: fsck the image filesystem
\r
145 command: "e2fsck -y -f {{ image_first_partition_device }}"
\r
147 - name: resize filesystem to full partition size
\r
148 command: resize2fs {{ image_first_partition_device }}
\r
150 - name: fsck the image filesystem
\r
151 command: "e2fsck -y -f {{ image_first_partition_device }}"
\r
153 - name: make tmp disposable fstab
\r
154 command: mktemp --tmpdir fake_fstab.XXXXXXXXXX
\r
155 register: mktemp_res
\r
158 fake_fstab: "{{ mktemp_res.stdout.strip() }}"
\r
160 - name: mount first parition on image device
\r
162 src: "{{ image_first_partition_device }}"
\r
163 name: "{{ mountdir }}"
\r
164 # fstype is required
\r
165 fstype: "{{ image_fs_type }}"
\r
166 # !!!!!!! this is required otherwise we add entries to /etc/fstab
\r
167 # and prevent the system from booting
\r
168 fstab: "{{ fake_fstab }}"
\r
171 - name: mount chroot /proc
\r
174 name: "{{ mountdir }}/proc"
\r
176 # !!!!!!! this is required otherwise we add entries to /etc/fstab
\r
177 # and prevent the system from booting
\r
178 fstab: "{{ fake_fstab }}"
\r
181 - name: if arm copy qemu-aarch64-static into chroot
\r
183 src: /usr/bin/qemu-aarch64-static
\r
184 dest: "{{ mountdir }}/usr/bin"
\r
185 when: img_arch == arch_arm64
\r
187 - name: create ubuntu policy-rc.d workaround
\r
189 content: "{{ '#!/bin/sh\nexit 101\n' }}"
\r
190 dest: "{{ mountdir }}/usr/sbin/policy-rc.d"
\r
192 when: "target_os == 'Ubuntu'"
\r
194 - name: add chroot as host
\r
196 name: "{{ mountdir }}"
\r
197 groups: chroot_image,image_builder
\r
199 ansible_python_interpreter: /usr/bin/python3
\r
200 # set this host variable here
\r
201 nameserver_ip: "{{ ansible_dns.nameservers[0] }}"
\r