Implement different approach to modify image
Because of very long image modifying by libguestfs, implement different way to do it by converting image to raw, mounting it and modifying in the place. This patch uses usual tripleo-ci way to do it, as it was before transition. Change-Id: Ice4487aa8d263aa7f4a426b7924104a469bd1b52
This commit is contained in:
parent
147229b902
commit
c2dc459ac2
@ -80,4 +80,4 @@ EOF
|
||||
|
||||
iptables-restore < freeipa-iptables-rules.txt
|
||||
|
||||
### ---stop_docs
|
||||
### ---stop_docs
|
||||
|
@ -24,3 +24,6 @@ modify_image_working_dir: "{{ working_dir }}"
|
||||
# modify_image_vc_root_password:
|
||||
modify_image_vc_verbose: false
|
||||
modify_image_vc_trace: false
|
||||
libguestfs_mode: true
|
||||
# TODO(sshnaidm): implement initramfs image modifying
|
||||
initramfs_image: false
|
||||
|
61
roles/modify-image/tasks/libguestfs.yml
Normal file
61
roles/modify-image/tasks/libguestfs.yml
Normal file
@ -0,0 +1,61 @@
|
||||
- name: ensure libguestfs is installed
|
||||
yum: name=libguestfs-tools-c state=latest
|
||||
become: true
|
||||
|
||||
- name: virt-customize args --> reset private var
|
||||
set_fact: _vc_args=""
|
||||
|
||||
- name: virt-customize args --> memory
|
||||
set_fact: _vc_args="{{ _vc_args }} -m {{ modify_image_vc_ram }}"
|
||||
when: modify_image_vc_ram is defined
|
||||
|
||||
- name: virt-customize args --> cpu
|
||||
set_fact: _vc_args="{{ _vc_args }} --smp {{ modify_image_vc_cpu }}"
|
||||
when: modify_image_vc_cpu is defined
|
||||
|
||||
- name: virt-customize args --> verbose output
|
||||
set_fact: _vc_args="{{ _vc_args }} -v"
|
||||
when: modify_image_vc_verbose|bool
|
||||
|
||||
- name: virt-customize args --> trace/debug output
|
||||
set_fact: _vc_args="{{ _vc_args }} -x"
|
||||
when: modify_image_vc_trace|bool
|
||||
|
||||
- name: virt-customize args --> upload files
|
||||
set_fact: _vc_args="{{ _vc_args }} --upload {{ item.src }}:{{ item.dest }}"
|
||||
with_items: "{{ modify_image_upload_files }}"
|
||||
|
||||
- name: virt-customize args --> install packages
|
||||
set_fact: _vc_args="{{ _vc_args }} --install {{ modify_image_install_packages|join(",") }}"
|
||||
when: modify_image_install_packages
|
||||
|
||||
- name: virt-customize args --> modify script
|
||||
set_fact: _vc_args="{{ _vc_args }} --run {{ modify_script }}"
|
||||
when: modify_script is defined
|
||||
|
||||
- name: virt-customize args --> root password
|
||||
set_fact: _vc_args="{{ _vc_args }} --root-password password:{{ modify_image_vc_root_password }}"
|
||||
when: modify_image_vc_root_password is defined
|
||||
|
||||
- name: Run virt-customize on the provided image
|
||||
shell: >
|
||||
virt-customize {{ _vc_args }}
|
||||
-a {{ image_to_modify }}
|
||||
> {{ modify_script|default('modify_image') }}.log 2>&1
|
||||
environment:
|
||||
LIBGUESTFS_BACKEND: direct
|
||||
args:
|
||||
chdir: "{{ modify_image_working_dir }}"
|
||||
|
||||
- name: Extract artifacts from the image
|
||||
shell: >
|
||||
virt-copy-out
|
||||
-a {{ image_to_modify }}
|
||||
{{ item }}
|
||||
{{ modify_image_working_dir }}
|
||||
environment:
|
||||
LIBGUESTFS_BACKEND: direct
|
||||
args:
|
||||
chdir: "{{ modify_image_working_dir }}"
|
||||
with_items: "{{ modify_image_extract_list }}"
|
||||
|
@ -7,64 +7,8 @@
|
||||
provided."
|
||||
when: image_to_modify is not defined or (modify_script is not defined and modify_image_upload_files == [])
|
||||
|
||||
- name: ensure libguestfs is installed
|
||||
yum: name=libguestfs-tools-c state=latest
|
||||
become: true
|
||||
|
||||
- name: virt-customize args --> reset private var
|
||||
set_fact: _vc_args=""
|
||||
|
||||
- name: virt-customize args --> memory
|
||||
set_fact: _vc_args="{{ _vc_args }} -m {{ modify_image_vc_ram }}"
|
||||
when: modify_image_vc_ram is defined
|
||||
|
||||
- name: virt-customize args --> cpu
|
||||
set_fact: _vc_args="{{ _vc_args }} --smp {{ modify_image_vc_cpu }}"
|
||||
when: modify_image_vc_cpu is defined
|
||||
|
||||
- name: virt-customize args --> verbose output
|
||||
set_fact: _vc_args="{{ _vc_args }} -v"
|
||||
when: modify_image_vc_verbose|bool
|
||||
|
||||
- name: virt-customize args --> trace/debug output
|
||||
set_fact: _vc_args="{{ _vc_args }} -x"
|
||||
when: modify_image_vc_trace|bool
|
||||
|
||||
- name: virt-customize args --> upload files
|
||||
set_fact: _vc_args="{{ _vc_args }} --upload {{ item.src }}:{{ item.dest }}"
|
||||
with_items: "{{ modify_image_upload_files }}"
|
||||
|
||||
- name: virt-customize args --> install packages
|
||||
set_fact: _vc_args="{{ _vc_args }} --install {{ modify_image_install_packages|join(",") }}"
|
||||
when: modify_image_install_packages
|
||||
|
||||
- name: virt-customize args --> modify script
|
||||
set_fact: _vc_args="{{ _vc_args }} --run {{ modify_script }}"
|
||||
when: modify_script is defined
|
||||
|
||||
- name: virt-customize args --> root password
|
||||
set_fact: _vc_args="{{ _vc_args }} --root-password password:{{ modify_image_vc_root_password }}"
|
||||
when: modify_image_vc_root_password is defined
|
||||
|
||||
- name: Run virt-customize on the provided image
|
||||
shell: >
|
||||
virt-customize {{ _vc_args }}
|
||||
-a {{ image_to_modify }}
|
||||
> {{ modify_script|default('modify_image') }}.log 2>&1
|
||||
environment:
|
||||
LIBGUESTFS_BACKEND: direct
|
||||
args:
|
||||
chdir: "{{ modify_image_working_dir }}"
|
||||
|
||||
- name: Extract artifacts from the image
|
||||
shell: >
|
||||
virt-copy-out
|
||||
-a {{ image_to_modify }}
|
||||
{{ item }}
|
||||
{{ modify_image_working_dir }}
|
||||
environment:
|
||||
LIBGUESTFS_BACKEND: direct
|
||||
args:
|
||||
chdir: "{{ modify_image_working_dir }}"
|
||||
with_items: "{{ modify_image_extract_list }}"
|
||||
- include: libguestfs.yml
|
||||
when: libguestfs_mode|bool
|
||||
|
||||
- include: manual.yml
|
||||
when: not libguestfs_mode|bool
|
||||
|
57
roles/modify-image/tasks/manual.yml
Normal file
57
roles/modify-image/tasks/manual.yml
Normal file
@ -0,0 +1,57 @@
|
||||
- when: not initramfs_image|bool
|
||||
block:
|
||||
|
||||
- name: Set abs path for image
|
||||
shell: echo "{{ image_to_modify }}"
|
||||
register: image_to_modify_abs_path
|
||||
|
||||
- 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') }}"
|
||||
mount_tempdir: "{{ lookup('pipe', 'mktemp -d') }}"
|
||||
|
||||
- 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: Upload files to image
|
||||
shell: >
|
||||
cp {{ item.src }} {{ mount_tempdir }}/{{ item.dest }};
|
||||
with_items: "{{ modify_image_upload_files }}"
|
||||
become: true
|
||||
|
||||
- name: Run script on image
|
||||
shell: >
|
||||
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 }};
|
||||
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{_,};
|
||||
become: true
|
||||
|
||||
- name: Extract files from image
|
||||
shell: cp {{ mount_tempdir }}/{{ item }} {{ modify_image_working_dir }}/;
|
||||
with_items: "{{ modify_image_extract_list }}"
|
||||
ignore_errors: true
|
||||
become: true
|
||||
|
||||
- name: Close 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 }}/;
|
||||
become: true
|
Loading…
x
Reference in New Issue
Block a user