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
|
* `image_to_modify` -- the image that virt-customize will operate on
|
||||||
* `modify_script` -- the script that will be run inside the image
|
* `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
|
* `modify_image_extract_list` -- list of artifacts to extract after the image
|
||||||
is modified
|
is modified
|
||||||
* `modify_image_working_dir` -- directory containing image and script. This is
|
* `modify_image_working_dir` -- directory containing image and script. This is
|
||||||
|
@ -71,6 +73,31 @@ Example Usage
|
||||||
roles:
|
roles:
|
||||||
- modify-image
|
- 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
|
License
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
# image_to_modify:
|
# image_to_modify:
|
||||||
# modify_script:
|
# modify_script:
|
||||||
|
|
||||||
|
# The upload list of files
|
||||||
|
modify_image_upload_files: []
|
||||||
|
|
||||||
# The extract list defaults to empty list
|
# The extract list defaults to empty list
|
||||||
modify_image_extract_list: []
|
modify_image_extract_list: []
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
msg:
|
msg:
|
||||||
"In order to use this role image_to_modify and modify_script must be
|
"In order to use this role image_to_modify and modify_script must be
|
||||||
provided."
|
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
|
- name: ensure libguestfs is installed
|
||||||
yum: name=libguestfs-tools-c state=latest
|
yum: name=libguestfs-tools-c state=latest
|
||||||
|
@ -27,21 +27,30 @@
|
||||||
set_fact: vc_args="{{ vc_args }} -x"
|
set_fact: vc_args="{{ vc_args }} -x"
|
||||||
when: modify_image_vc_trace|bool
|
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
|
- name: Run virt-customize on the provided image
|
||||||
shell: virt-customize {{ vc_args }}
|
shell: >
|
||||||
-a {{ image_to_modify }}
|
virt-customize {{ vc_args }}
|
||||||
--run {{ modify_script }}
|
-a {{ image_to_modify }}
|
||||||
> {{ modify_script }}.log 2>&1
|
> {{ modify_script|default('modify_image') }}.log 2>&1
|
||||||
environment:
|
environment:
|
||||||
LIBGUESTFS_BACKEND: direct
|
LIBGUESTFS_BACKEND: direct
|
||||||
args:
|
args:
|
||||||
chdir: "{{ modify_image_working_dir }}"
|
chdir: "{{ modify_image_working_dir }}"
|
||||||
|
|
||||||
- name: Extract artifacts from the image
|
- name: Extract artifacts from the image
|
||||||
shell: virt-copy-out
|
shell: >
|
||||||
-a {{ image_to_modify }}
|
virt-copy-out
|
||||||
{{ item }}
|
-a {{ image_to_modify }}
|
||||||
{{ modify_image_working_dir }}
|
{{ item }}
|
||||||
|
{{ modify_image_working_dir }}
|
||||||
environment:
|
environment:
|
||||||
LIBGUESTFS_BACKEND: direct
|
LIBGUESTFS_BACKEND: direct
|
||||||
args:
|
args:
|
||||||
|
|
Loading…
Reference in New Issue