Support uploading files in modify image role
Support for uploading files to image. Change-Id: I5cf1959437097f410cc36e1a1536141bfc9da325
This commit is contained in:
parent
376509fb44
commit
61ef59ff2c
@ -19,6 +19,8 @@ Role Variables
|
||||
|
||||
* `image_to_modify` -- the image that virt-customize will operate on
|
||||
* `modify_script` -- the script that will be run inside the image
|
||||
* `modify_image_upload_files` -- list of src/dest of files to upload to image
|
||||
(files are uploaded before running the script)
|
||||
* `modify_image_extract_list` -- list of artifacts to extract after the image
|
||||
is modified
|
||||
* `modify_image_working_dir` -- directory containing image and script. This is
|
||||
@ -71,6 +73,31 @@ Example Usage
|
||||
roles:
|
||||
- modify-image
|
||||
|
||||
- name: Upload files to image
|
||||
hosts: virthost
|
||||
vars:
|
||||
image_to_modify: "{{ working_dir }}/undercloud.qcow2"
|
||||
modify_image_upload_files:
|
||||
- src: /tmp/file_to_upload.tar.gz
|
||||
dest: /home/user/renamed_file.tar.gz
|
||||
- src: /home/local_user/file
|
||||
dest: /home/image_user/
|
||||
roles:
|
||||
- modify-image
|
||||
|
||||
- name: Upload files to image and run script
|
||||
hosts: virthost
|
||||
vars:
|
||||
image_to_modify: "{{ working_dir }}/undercloud.qcow2"
|
||||
modify_image_upload_files:
|
||||
- src: /tmp/file_to_upload.tar.gz
|
||||
dest: /home/user/renamed_file.tar.gz
|
||||
- src: /home/local_user/file
|
||||
dest: /tmp/
|
||||
modify_script: "{{ working_dir }}/undercloud_convert.sh"
|
||||
roles:
|
||||
- modify-image
|
||||
|
||||
```
|
||||
|
||||
License
|
||||
|
@ -6,6 +6,9 @@
|
||||
# image_to_modify:
|
||||
# modify_script:
|
||||
|
||||
# The upload list of files
|
||||
modify_image_upload_files: []
|
||||
|
||||
# The extract list defaults to empty list
|
||||
modify_image_extract_list: []
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
msg:
|
||||
"In order to use this role image_to_modify and modify_script must be
|
||||
provided."
|
||||
when: image_to_modify is not defined or modify_script is not defined
|
||||
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
|
||||
@ -27,21 +27,30 @@
|
||||
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 --> modify script
|
||||
set_fact: vc_args="{{ vc_args }} --run {{ modify_script }}"
|
||||
when: modify_script is defined
|
||||
|
||||
- name: Run virt-customize on the provided image
|
||||
shell: virt-customize {{ vc_args }}
|
||||
-a {{ image_to_modify }}
|
||||
--run {{ modify_script }}
|
||||
> {{ modify_script }}.log 2>&1
|
||||
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 }}
|
||||
shell: >
|
||||
virt-copy-out
|
||||
-a {{ image_to_modify }}
|
||||
{{ item }}
|
||||
{{ modify_image_working_dir }}
|
||||
environment:
|
||||
LIBGUESTFS_BACKEND: direct
|
||||
args:
|
||||
|
Loading…
Reference in New Issue
Block a user