This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
/
manual.yml
83 lines (70 loc) · 2.95 KB
/
manual.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
- name: Set abs path for image
shell: echo "{{ image_to_modify }}"
register: image_to_modify_abs_path
- name: Create a temp dir for extracting images
command: mktemp -d
register: mktemp_command
- name: Set names for images and temp dir
set_fact:
mount_tempdir: "{{ mktemp_command.stdout }}"
- when: not initramfs_image|bool
block:
- name: Set names for images and temp dir
set_fact:
image_to_modify_qcow: "{{ image_to_modify_abs_path.stdout }}"
image_to_modify_raw: "{{ image_to_modify_abs_path.stdout|replace('qcow2', 'raw') }}"
- name: Convert image
shell: >
qemu-img convert -f qcow2 -O raw {{ image_to_modify_qcow }} {{ image_to_modify_raw }};
rm -rf "{{ image_to_modify_qcow }}";
- name: Mount image
shell: >
kpartx -avs {{ image_to_modify_raw }};
mount /dev/mapper/loop0p1 {{ mount_tempdir }} || mount /dev/loop0 {{ mount_tempdir }};
become: true
- name: Extract initramfs image
shell: set -o pipefail && gunzip -c {{ image_to_modify_abs_path.stdout }} | cpio -i
become: true
args:
chdir: "{{ mount_tempdir }}"
when: initramfs_image|bool
- become: true
block:
- name: Upload files to image
shell: >
cp {{ item.src }} {{ mount_tempdir }}/{{ item.dest }};
with_items: "{{ modify_image_upload_files }}"
- name: Run script on image
shell: >
mount -o bind /dev {{ mount_tempdir }}/dev/;
mv {{ mount_tempdir }}/etc/resolv.conf{,_};
echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4" > {{ mount_tempdir }}/etc/resolv.conf;
cp {{ modify_script }} {{ mount_tempdir }}/tmp/{{ modify_script|basename }};
{% if initramfs_image|bool %}sed -i "s/sudo //g" {{ mount_tempdir }}/tmp/{{ modify_script|basename }};{% endif %}
set -o pipefail && chroot {{ mount_tempdir }} /bin/bash /tmp/{{ modify_script|basename }} 2>&1
{{ timestamper_cmd }} > {{ working_dir }}/{{ modify_script|basename }}.$(date +%s).log;
mv -f {{ mount_tempdir }}/etc/resolv.conf{_,};
- name: Extract files from image
shell: cp {{ mount_tempdir }}/{{ item }} {{ modify_image_working_dir }}/;
with_items: "{{ modify_image_extract_list }}"
ignore_errors: true
- name: Close initramfs image
shell: >
set -o pipefail &&
pushd {{ mount_tempdir }};
find . -print | cpio -o -H newc | gzip > {{ image_to_modify_abs_path.stdout }};
popd;
rm -rf "{{ mount_tempdir }}";
when: initramfs_image|bool
- name: Close qcow2 image
shell: >
chroot {{ mount_tempdir }} setfiles /etc/selinux/targeted/contexts/files/file_contexts / ;
umount {{ mount_tempdir }};
kpartx -dv {{ image_to_modify_raw }};
qemu-img convert -c -f raw -O qcow2 {{ image_to_modify_raw }} {{ image_to_modify_qcow }};
rm -rf "{{ image_to_modify_raw }}";
losetup -d /dev/loop0;
rm -rf "{{ mount_tempdir }}";
chown -R {{ undercloud_user }}: /home/{{ undercloud_user }}/;
when: not initramfs_image|bool