-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sudeesh John
committed
Jul 26, 2020
0 parents
commit cdc5899
Showing
8 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Convert qcow2 image to OVA for PowerVS | ||
|
||
This playbook convert a qcow2 image into a required sized ova image | ||
|
||
Playbook assume following: | ||
1. Given input image is qcow2 | ||
2. Target machine has enough disk space to contain the intermediate images | ||
3. Target machine has required commands like, qemu-img, gzip etc | ||
|
||
|
||
# Using playbook | ||
|
||
1. Update vars/main.yaml with the URL/FILE etc | ||
2. Run the playbook | ||
`ansible-playbook tasks/main.yml` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[defaults] | ||
inventory = inventory | ||
command_warnings = False | ||
filter_plugins = filter_plugins | ||
host_key_checking = False | ||
deprecation_warnings=False | ||
retry_files = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
# defaults file | ||
workdir: /tmp/image-workdir/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[vmhost] | ||
localhost ansible_connection=local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
--- | ||
# Setup OCP4 Helper Node | ||
|
||
- hosts: all | ||
vars_files: | ||
- ../vars/main.yml | ||
- ../defaults/main.yml | ||
|
||
tasks: | ||
- name: check work directory. | ||
stat: | ||
path: "{{ workdir }}" | ||
register: work_folder | ||
|
||
- name: Create work directory if not exists | ||
file: | ||
path: "{{ workdir }}" | ||
state: directory | ||
mode: 0755 | ||
when: work_folder.stat.exists == false | ||
|
||
- name: clean work directory | ||
file: | ||
path: "{{ workdir }}" | ||
state: "{{ item }}" | ||
with_items: | ||
- absent | ||
- directory | ||
|
||
- name: Create image directory | ||
file: | ||
path: "{{ workdir }}/image" | ||
state: "{{ item }}" | ||
with_items: | ||
- absent | ||
- directory | ||
|
||
- name: Download image | ||
get_url: | ||
url: "{{ image_url }}" | ||
dest: "{{ workdir }}" | ||
when: image_url is defined | ||
|
||
- name: Copy image | ||
copy: | ||
src: "{{ image_file }}" | ||
dest: "{{ workdir }}" | ||
when: image_file is defined | ||
|
||
- name: Get the image file name | ||
shell: basename "{{ image_url }}" | ||
register: image_name | ||
when: image_url is defined | ||
|
||
- name: Get the image file name | ||
shell: basename "{{ image_file }}" | ||
register: image_name | ||
when: image_file is defined | ||
|
||
- name: Get the rhcos qcow2 file name | ||
shell: ls *.qcow2.gz | ||
args: | ||
chdir: "{{ workdir }}" | ||
register: qcow2_file | ||
|
||
- name: Volume Name | ||
shell: basename {{ qcow2_file.stdout }} .qcow2.gz | ||
register: volume_name | ||
|
||
- name: Decompress the rhcos image file | ||
shell: gzip -d "{{ qcow2_file.stdout }}" | ||
args: | ||
chdir: "{{ workdir }}" | ||
|
||
- name: Get the rhcos qcow2 file name | ||
shell: ls *.qcow2 | ||
args: | ||
chdir: "{{ workdir }}" | ||
register: qcow2_file | ||
|
||
- name: Extend the qcow2 image | ||
shell: qemu-img resize "{{ qcow2_file.stdout }}" +{{ image_size }}G | ||
args: | ||
chdir: "{{ workdir }}" | ||
when: image_size is defined | ||
|
||
|
||
- name: Convert qcow2 to raw | ||
shell: qemu-img convert -f qcow2 -O raw {{ qcow2_file.stdout }} {{ volume_name.stdout }} | ||
args: | ||
chdir: "{{ workdir }}" | ||
|
||
- name: Extend the image | ||
shell: qemu-img resize "{{ volume_name.stdout }}" {{ image_size }}G | ||
args: | ||
chdir: "{{ workdir }}" | ||
when: image_size is defined | ||
|
||
- name: Get the raw volume size | ||
shell: ls -l {{ volume_name.stdout }} | awk '{print $5}' | ||
register: volume_size | ||
args: | ||
chdir: "{{ workdir }}" | ||
|
||
- name: Volume to image dir | ||
command: mv "{{ workdir }}/{{ volume_name.stdout }}" "{{ workdir }}/image/{{ volume_name.stdout }}" | ||
|
||
- name: Creating metadata file file | ||
template: | ||
src: ../templates/image.meta.j2 | ||
dest: "{{ workdir }}/image/{{ imagename }}.meta" | ||
|
||
- name: Creating ovf file | ||
template: | ||
src: ../templates/image.ovf.j2 | ||
dest: "{{ workdir }}/image/{{imagename}}.ovf" | ||
|
||
- name: Create OVA image file | ||
archive: | ||
path: "{{ workdir }}/image/." | ||
dest: "{{ workdir }}/{{ imagename }}.ova" | ||
format: tar | ||
|
||
- name: Compres OVA image file to gz | ||
archive: | ||
path: "{{ workdir }}/{{ imagename }}.ova" | ||
dest: "{{ workdir }}/{{ imagename }}.ova.gz" | ||
format: gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
os-type = rhel | ||
architecture = ppc64le | ||
vol1-file = {{ imagename }} | ||
vol1-type = boot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ovf:Envelope xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<ovf:References> | ||
<ovf:File href="{{ volume_name.stdout }}" id="file1" size="{{ volume_size.stdout }}"/> | ||
</ovf:References> | ||
<ovf:DiskSection> | ||
<ovf:Info>Disk Section</ovf:Info> | ||
<ovf:Disk capacity="{{ volume_size.stdout }}" capacityAllocationUnits="byte" diskId="disk1" fileRef="file1"/> | ||
</ovf:DiskSection> | ||
<ovf:VirtualSystemCollection> | ||
<ovf:VirtualSystem ovf:id="vs0"> | ||
<ovf:Name>{{ imagename }}</ovf:Name> | ||
<ovf:Info></ovf:Info> | ||
<ovf:ProductSection> | ||
<ovf:Info/> | ||
<ovf:Product/> | ||
</ovf:ProductSection> | ||
<ovf:OperatingSystemSection ovf:id="79"> | ||
<ovf:Info/> | ||
<ovf:Description>RHEL</ovf:Description> | ||
<ns0:architecture xmlns:ns0="ibmpvc">ppc64le</ns0:architecture> | ||
</ovf:OperatingSystemSection> | ||
<ovf:VirtualHardwareSection> | ||
<ovf:Info>Storage resources</ovf:Info> | ||
<ovf:Item> | ||
<rasd:Description>Temporary clone for export</rasd:Description> | ||
<rasd:ElementName>{{ volume_name.stdout }}</rasd:ElementName> | ||
<rasd:HostResource>ovf:/disk/disk1</rasd:HostResource> | ||
<rasd:InstanceID>1</rasd:InstanceID> | ||
<rasd:ResourceType>17</rasd:ResourceType> | ||
<ns1:boot xmlns:ns1="ibmpvc">True</ns1:boot> | ||
</ovf:Item> | ||
</ovf:VirtualHardwareSection> | ||
</ovf:VirtualSystem> | ||
<ovf:Info/> | ||
<ovf:Name>{{ imagename }}</ovf:Name> | ||
</ovf:VirtualSystemCollection> | ||
</ovf:Envelope> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
image_url: https://mirror.openshift.com/pub/openshift-v4/ppc64le/dependencies/rhcos/4.4/4.4.9/rhcos-4.4.9-ppc64le-openstack.ppc64le.qcow2.gz | ||
#image_file: ~/Downloads/rhcos-4.4.9-ppc64le-openstack.ppc64le.qcow2.gz | ||
image_size: 5 | ||
imagename: rhcos-44 |