diff options
Diffstat (limited to 'roles/vmware-ova')
-rw-r--r-- | roles/vmware-ova/tasks/main.yml | 67 | ||||
-rw-r--r-- | roles/vmware-ova/templates/vyos_vmware_image.ovf.j2 | 122 | ||||
-rw-r--r-- | roles/vmware-ova/tests/inventory | 2 | ||||
-rw-r--r-- | roles/vmware-ova/tests/test.yml | 4 | ||||
-rw-r--r-- | roles/vmware-ova/vars/main.yml | 6 |
5 files changed, 201 insertions, 0 deletions
diff --git a/roles/vmware-ova/tasks/main.yml b/roles/vmware-ova/tasks/main.yml new file mode 100644 index 0000000..53c4989 --- /dev/null +++ b/roles/vmware-ova/tasks/main.yml @@ -0,0 +1,67 @@ +- name: Convert raw to vmdk + command: qemu-img convert -f raw "{{ vyos_raw_img }}" -O vmdk -o adapter_type=lsilogic "{{ vyos_vmware_tmp_vmdk }}" +- name: Fix vmdk with open-vmdk + command: vmdk-convert "{{ vyos_vmware_tmp_vmdk }}" "{{ vyos_vmware_vmdk }}" +- name: Get vmdk_file_size + shell: du --bytes "{{ vyos_vmware_vmdk }}" | cut -f1 + register: vmdk_file_size +- name: Get vmdk_populated_size + shell: vmdk-convert -i "{{ vyos_vmware_vmdk }}" + register: result +- name: Set vmdk_populated_size + set_fact: + vmdk_populated_size: "{{ (result.stdout | from_json).used }}" +- name: Generate OVF + become: false + template: + src: templates/vyos_vmware_image.ovf.j2 + dest: "{{ vyos_vmware_ovf }}" +- name: Generate MF + shell: openssl sha1 "{{ vyos_vmware_vmdk | basename }}" "{{ vyos_vmware_ovf | basename }}" + args: + chdir: /tmp + register: result +- name: Create MF + become: false + copy: + dest: "{{ vyos_vmware_mf }}" + content: "{{ result.stdout }}" +- name: Create OVA without private key + become: false + archive: + path: + - "{{ vyos_vmware_ovf }}" + - "{{ vyos_vmware_mf }}" + - "{{ vyos_vmware_vmdk }}" + dest: "{{ vyos_vmware_ova }}" + format: tar + when: vyos_vmware_private_key_path is not defined +- name: Sign MF + shell: openssl dgst -sha256 -sign "{{ vyos_vmware_private_key_path }}" -hex "{{ vyos_vmware_mf | basename }}" | sed 's/^RSA-//' + args: + chdir: /tmp + register: signature + when: vyos_vmware_private_key_path is defined +- name: Get certificate + shell: openssl x509 -in "{{ vyos_vmware_private_key_path }}" + register: certificate + when: vyos_vmware_private_key_path is defined +- name: Create cert file for OVA + become: false + copy: + dest: "{{ vyos_vmware_cert }}" + content: | + {{ signature.stdout }} + {{ certificate.stdout }} + when: vyos_vmware_private_key_path is defined +- name: Create OVA with private key + become: false + archive: + path: + - "{{ vyos_vmware_ovf }}" + - "{{ vyos_vmware_mf }}" + - "{{ vyos_vmware_cert }}" + - "{{ vyos_vmware_vmdk }}" + dest: "{{ vyos_vmware_ova }}" + format: tar + when: vyos_vmware_private_key_path is defined diff --git a/roles/vmware-ova/templates/vyos_vmware_image.ovf.j2 b/roles/vmware-ova/templates/vyos_vmware_image.ovf.j2 new file mode 100644 index 0000000..b6b7fa7 --- /dev/null +++ b/roles/vmware-ova/templates/vyos_vmware_image.ovf.j2 @@ -0,0 +1,122 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Envelope vmw:buildId="build-3018522" xmlns="http://schemas.dmtf.org/ovf/envelope/1" xmlns:cim="http://schemas.dmtf.org/wbem/wscim/1/common" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vmw="http://www.vmware.com/schema/ovf" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <References> + <File ovf:href="vyos_vmware_image.vmdk" ovf:id="file1" ovf:size="{{ vmdk_file_size.stdout }}"/> + </References> + <DiskSection> + <Info>Virtual disk information</Info> + <Disk ovf:capacity="{{ vyos_vmdk_size }}" ovf:capacityAllocationUnits="byte * 2^30" ovf:diskId="vmdisk1" ovf:fileRef="file1" ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized" ovf:populatedSize="{{ vmdk_populated_size }}"/> + </DiskSection> + <NetworkSection> + <Info>The list of logical networks</Info> + <Network ovf:name="VM Network"> + <Description>The VM Network network</Description> + </Network> + </NetworkSection> + <VirtualSystem ovf:id="vm"> + <Info>A virtual machine</Info> + <Name>vyos</Name> + <OperatingSystemSection ovf:id="1" vmw:osType="other26xLinux64Guest"> + <Info>The kind of installed guest operating system</Info> + </OperatingSystemSection> + <VirtualHardwareSection> + <Info>Virtual hardware requirements</Info> + <System> + <vssd:ElementName>Virtual Hardware Family</vssd:ElementName> + <vssd:InstanceID>0</vssd:InstanceID> + <vssd:VirtualSystemIdentifier>vyos</vssd:VirtualSystemIdentifier> + <vssd:VirtualSystemType>vmx-09</vssd:VirtualSystemType> + </System> + <Item> + <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits> + <rasd:Description>Number of Virtual CPUs</rasd:Description> + <rasd:ElementName>1 virtual CPU(s)</rasd:ElementName> + <rasd:InstanceID>1</rasd:InstanceID> + <rasd:ResourceType>3</rasd:ResourceType> + <rasd:VirtualQuantity>1</rasd:VirtualQuantity> + </Item> + <Item> + <rasd:AllocationUnits>byte * 2^30</rasd:AllocationUnits> + <rasd:Description>Memory Size</rasd:Description> + <rasd:ElementName>1GB of memory</rasd:ElementName> + <rasd:InstanceID>2</rasd:InstanceID> + <rasd:ResourceType>4</rasd:ResourceType> + <rasd:VirtualQuantity>1</rasd:VirtualQuantity> + </Item> + <Item> + <rasd:Address>0</rasd:Address> + <rasd:Description>SCSI Controller</rasd:Description> + <rasd:ElementName>scsiController0</rasd:ElementName> + <rasd:InstanceID>3</rasd:InstanceID> + <rasd:ResourceSubType>lsilogic</rasd:ResourceSubType> + <rasd:ResourceType>6</rasd:ResourceType> + </Item> + <Item> + <rasd:Address>1</rasd:Address> + <rasd:Description>IDE Controller</rasd:Description> + <rasd:ElementName>ideController1</rasd:ElementName> + <rasd:InstanceID>4</rasd:InstanceID> + <rasd:ResourceType>5</rasd:ResourceType> + </Item> + <Item ovf:required="false"> + <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> + <rasd:ElementName>serial0</rasd:ElementName> + <rasd:InstanceID>5</rasd:InstanceID> + <rasd:ResourceType>21</rasd:ResourceType> + <vmw:Config ovf:required="false" vmw:key="yieldOnPoll" vmw:value="false"/> + </Item> + <Item ovf:required="false"> + <rasd:AddressOnParent>0</rasd:AddressOnParent> + <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation> + <rasd:ElementName>cdrom0</rasd:ElementName> + <rasd:InstanceID>6</rasd:InstanceID> + <rasd:Parent>5</rasd:Parent> + <rasd:ResourceType>15</rasd:ResourceType> + </Item> + <Item> + <rasd:AddressOnParent>0</rasd:AddressOnParent> + <rasd:ElementName>disk0</rasd:ElementName> + <rasd:HostResource>ovf:/disk/vmdisk1</rasd:HostResource> + <rasd:InstanceID>7</rasd:InstanceID> + <rasd:Parent>3</rasd:Parent> + <rasd:ResourceType>17</rasd:ResourceType> + </Item> + <Item> + <rasd:AddressOnParent>2</rasd:AddressOnParent> + <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> + <rasd:Connection>VM Network</rasd:Connection> + <rasd:Description>VmxNet3 ethernet adapter on "VM Network"</rasd:Description> + <rasd:ElementName>ethernet0</rasd:ElementName> + <rasd:InstanceID>8</rasd:InstanceID> + <rasd:ResourceSubType>VmxNet3</rasd:ResourceSubType> + <rasd:ResourceType>10</rasd:ResourceType> + <vmw:Config ovf:required="false" vmw:key="wakeOnLanEnabled" vmw:value="false"/> + </Item> + <Item ovf:required="false"> + <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation> + <rasd:ElementName>video</rasd:ElementName> + <rasd:InstanceID>9</rasd:InstanceID> + <rasd:ResourceType>24</rasd:ResourceType> + </Item> + <Item ovf:required="false"> + <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation> + <rasd:ElementName>vmci</rasd:ElementName> + <rasd:InstanceID>10</rasd:InstanceID> + <rasd:ResourceSubType>vmware.vmci</rasd:ResourceSubType> + <rasd:ResourceType>1</rasd:ResourceType> + </Item> + <vmw:Config ovf:required="false" vmw:key="cpuHotAddEnabled" vmw:value="true"/> + <vmw:Config ovf:required="false" vmw:key="memoryHotAddEnabled" vmw:value="true"/> + <vmw:Config ovf:required="false" vmw:key="cpuHotRemoveEnabled" vmw:value="false"/> + <vmw:Config ovf:required="false" vmw:key="powerOpInfo.powerOffType" vmw:value="soft"/> + <vmw:Config ovf:required="false" vmw:key="powerOpInfo.resetType" vmw:value="soft"/> + <vmw:Config ovf:required="false" vmw:key="powerOpInfo.suspendType" vmw:value="soft"/> + </VirtualHardwareSection> + <ProductSection> + <Info>VyOS is a Linux-based network operating system that provides software-based network routing, firewall, and VPN functionality.</Info> + <Product>VyOS</Product> + <Vendor>VyOS maintainers and contributors</Vendor> + <Version>{{ vyos_version }}</Version> + </ProductSection> + </VirtualSystem> +</Envelope> diff --git a/roles/vmware-ova/tests/inventory b/roles/vmware-ova/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/vmware-ova/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/vmware-ova/tests/test.yml b/roles/vmware-ova/tests/test.yml new file mode 100644 index 0000000..58552e3 --- /dev/null +++ b/roles/vmware-ova/tests/test.yml @@ -0,0 +1,4 @@ +--- +- hosts: localhost + roles: + - vmware-ova diff --git a/roles/vmware-ova/vars/main.yml b/roles/vmware-ova/vars/main.yml new file mode 100644 index 0000000..176f25c --- /dev/null +++ b/roles/vmware-ova/vars/main.yml @@ -0,0 +1,6 @@ +vyos_vmware_ovf: /tmp/vyos_vmware_image.ovf +vyos_vmware_tmp_vmdk: /tmp/vyos_vmware_image_tmp.vmdk +vyos_vmware_mf: /tmp/vyos_vmware_image.mf +vyos_vmware_vmdk: /tmp/vyos_vmware_image.vmdk +vyos_vmware_ova: /tmp/vyos_vmware_image.ova +vyos_vmware_cert: /tmp/vyos_vmware_image.cert |