diff options
author | Kim <kim.sidney@gmail.com> | 2021-06-11 15:05:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-11 15:05:54 +0200 |
commit | e0ad618192bd652f7a26ed4f34265d4f7de9c45b (patch) | |
tree | 99170c4c52fec8fa99ffb99816f9751d1610058d /roles/vmware | |
parent | cd195f1d2b52a7f695474b4a9c4955db7f74d55b (diff) | |
download | vyos-vm-images-e0ad618192bd652f7a26ed4f34265d4f7de9c45b.tar.gz vyos-vm-images-e0ad618192bd652f7a26ed4f34265d4f7de9c45b.zip |
Updated vmware build playbooks (#18)
* Add debian version variables.
Removed compression flag from ovftool command
* Updated vmware playbook to be able to generate a simple OVA
without properties and set the vmware hardware based on debian version configured
to support debian 10 guests.
* Update the default time servers to the VyOS time servers.
* Add rescue option if the play fails to unmount filesystems.
Diffstat (limited to 'roles/vmware')
-rw-r--r-- | roles/vmware/tasks/main.yml | 53 | ||||
-rw-r--r-- | roles/vmware/templates/vyos_vmware_image.ovf.j2 | 245 | ||||
-rw-r--r-- | roles/vmware/tests/inventory | 2 | ||||
-rw-r--r-- | roles/vmware/tests/test.yml | 4 | ||||
-rw-r--r-- | roles/vmware/vars/main.yml | 5 |
5 files changed, 309 insertions, 0 deletions
diff --git a/roles/vmware/tasks/main.yml b/roles/vmware/tasks/main.yml new file mode 100644 index 0000000..f62c83f --- /dev/null +++ b/roles/vmware/tasks/main.yml @@ -0,0 +1,53 @@ +- 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: Delete temporary image + file: + path: "{{ vyos_vmware_tmp_vmdk }}" + state: absent + +- 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: Converting the OVF to signed OVA + become: false + command: "ovftool --privateKey={{ vyos_vmware_private_key_path }} {{ vyos_vmware_ovf }} {{ vyos_vmware_ova }}" + +- name: Delete temporary files for VMware + file: + path: "{{ item }}" + state: absent + loop: + - "{{ vyos_vmware_ovf }}" + - "{{ vyos_vmware_mf }}" + - "{{ vyos_vmware_vmdk }}" diff --git a/roles/vmware/templates/vyos_vmware_image.ovf.j2 b/roles/vmware/templates/vyos_vmware_image.ovf.j2 new file mode 100644 index 0000000..81a9b3a --- /dev/null +++ b/roles/vmware/templates/vyos_vmware_image.ovf.j2 @@ -0,0 +1,245 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ovf:Envelope xmlns="http://schemas.dmtf.org/ovf/envelope/1" 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> + <ovf:NetworkSection> + <ovf:Info>The list of logical networks</ovf:Info> + <ovf:Network ovf:name="WAN"> + <ovf:Description>WAN network</ovf:Description> + </ovf:Network> + <ovf:Network ovf:name="LAN"> + <ovf:Description>LAN network</ovf:Description> + </ovf:Network> + </ovf:NetworkSection> + {%- if ovf_template|default('ci') != 'simple' -%} + <DeploymentOptionSection> + <Info>List of profiles</Info> + <Configuration ovf:default="true" ovf:id="1CPU-512MB"> + <Label ovf:msgid="Small.label">Small</Label> + <Description ovf:msgid="Small.description">Minimal hardware profile - 1 vCPU, 512 MB RAM</Description> + </Configuration> + <Configuration ovf:id="4CPU-16GB"> + <Label ovf:msgid="Medium.label">Medium</Label> + <Description ovf:msgid="Medium.description">Medium hardware profile - 4 vCPUs, 16 GB RAM</Description> + </Configuration> + <Configuration ovf:id="8CPU-32GB"> + <Label ovf:msgid="Large.label">Large</Label> + <Description ovf:msgid="Large.description">Large hardware profile - 8 vCPUs, 32 GB RAM</Description> + </Configuration> + </DeploymentOptionSection> + {%- endif -%} + <vmw:IpAssignmentSection ovf:required="false" vmw:protocols="IPv4 IPv6" vmw:schemes="ovfenv dhcp"> + <Info>Supported IP assignment schemes</Info> + </vmw:IpAssignmentSection> + <DiskSection> + <Info>Virtual disk information</Info> + <Disk ovf:capacity="10" 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> + <VirtualSystem ovf:id="VyOS"> + <Info>A virtual machine</Info> + <ProductSection ovf:required="false"> + <Info>VyOS is a Linux-based network operating system that provides software-based network routing, firewall, and VPN functionality.</Info> + <Product>VyOS</Product> + <Vendor>Sentrium S.L.</Vendor> + <Version>{{ vyos_version }}</Version> + <ProductUrl>https://www.vyos.io</ProductUrl> + <VendorUrl>https://sentrium.io/</VendorUrl> + <AppUrl/> + <Category>Appliance user Settings</Category> + {%- if ovf_template|default('ci') != 'simple' -%} + <Property ovf:key="password" ovf:password="true" ovf:qualifiers="MinLen(8)" ovf:type="string" ovf:userConfigurable="true" ovf:value=""> + <Label ovf:msgid="Password.label">Password</Label> + <Description ovf:msgid="Password.description">The password for the appliance 'vyos' account. Passwords must be at least 8 characters in length.</Description> + </Property> + <Property ovf:key="public-keys" ovf:type="string" ovf:userConfigurable="true" ovf:value=""> + <Label>Public key</Label> + <Description>The public ssh key for the appliance 'vyos' account.</Description> + </Property> + <Category>Appliance IPv4 Network Settings (WAN interface)</Category> + <Property ovf:key="local-hostname" ovf:qualifiers="MinLen(0),MaxLen(65535)" ovf:type="string" ovf:userConfigurable="true" ovf:value=""> + <Label>Hostname</Label> + <Description>The host name for this virtual machine.</Description> + </Property> + <Property ovf:key="ip0" ovf:type="string" ovf:userConfigurable="true"> + <Label>Network IPv4 Address</Label> + <Description>The IPv4 address. Leave blank if DHCP is desired.</Description> + </Property> + <Property ovf:key="netmask0" ovf:type="string" ovf:userConfigurable="true"> + <Label>Network IPv4 Netmask</Label> + <Description>The IPv4 netmask or prefix for this interface. Leave blank if DHCP is desired.</Description> + </Property> + <Property ovf:key="gateway" ovf:type="string" ovf:userConfigurable="true"> + <Label>Default Gateway v4</Label> + <Description>Default gateway address. Leave blank if DHCP is desired.</Description> + </Property> + <Property ovf:key="DNS" ovf:type="string" ovf:userConfigurable="true"> + <Label>Domain Name Servers</Label> + <Description>The domain name server IP Addresses for this VM (comma separated). Leave blank if DHCP is desired.</Description> + </Property> + <Property ovf:key="NTP" ovf:type="string" ovf:userConfigurable="true"> + <Label>Domain Time Servers</Label> + <Description>NTP servers for this VM (comma separated). Leave blank if DHCP is desired.</Description> + </Property> + <Category>Appliance API Settings</Category> + <Property ovf:key="APIKEY" ovf:type="string" ovf:userConfigurable="true"> + <Label>API key</Label> + <Description>API key to access the VyOS api. If left blank the api wil not be enabled.</Description> + </Property> + <Property ovf:key="APIPORT" ovf:value="443" ovf:type="int" ovf:userConfigurable="true"> + <Label>API listening port</Label> + <Description>API port to listen on for calls. Leave blank to keep it default '443'.</Description> + </Property> + <Property ovf:key="APIDEBUG" ovf:value="false" ovf:type="boolean" ovf:userConfigurable="true"> + <Label>API debug logging</Label> + <Description>Enable API debug logging</Description> + </Property> + <Property ovf:key="user-data" ovf:type="string" ovf:userConfigurable="true" ovf:value=""> + <Label>Cloud-init User-Data</Label> + <Description>User-Data, encoded with base64.</Description> + </Property> + {%- endif -%} + </ProductSection> + <ProductSection ovf:class="vm" ovf:required="false"> + <Info>VM specific properties</Info> + <Property ovf:key="vmname" ovf:type="string" ovf:value="VyOS"/> + </ProductSection> + <AnnotationSection> + <Info/> + <Annotation>VyOS</Annotation> + </AnnotationSection> + <OperatingSystemSection ovf:id="96" ovf:version="6" vmw:osType="{{ vmware_guest }}"> + <Info>The operating system installed</Info> + <Description>Debian GNU/Linux {{ debian_release }} (64-bit)</Description> + </OperatingSystemSection> + <VirtualHardwareSection ovf:required="false" ovf:transport="com.vmware.guestInfo"> + <Info>Virtual Hardware Requirements</Info> + <System> + <vssd:ElementName>Virtual Hardware Family</vssd:ElementName> + <vssd:InstanceID>0</vssd:InstanceID> + <vssd:VirtualSystemType>vmx-{{ 11 if debian_release == 8 else 13 }}</vssd:VirtualSystemType> + </System> + {%- if ovf_template|default('ci') != 'simple' -%} + <Item configuration="1CPU-512MB"> + <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits> + <rasd:Description>Number of virtual CPUs</rasd:Description> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1 virtual CPU</rasd:ElementName> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</rasd:InstanceID> + <rasd:ResourceType>3</rasd:ResourceType> + <rasd:VirtualQuantity>1</rasd:VirtualQuantity> + </Item> + <Item configuration="4CPU-16GB"> + <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits> + <rasd:Description>Number of virtual CPUs</rasd:Description> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4 virtual CPUs</rasd:ElementName> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</rasd:InstanceID> + <rasd:ResourceType>3</rasd:ResourceType> + <rasd:VirtualQuantity>4</rasd:VirtualQuantity> + </Item> + <Item configuration="8CPU-32GB"> + <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits> + <rasd:Description>Number of virtual CPUs</rasd:Description> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">8 virtual CPUs</rasd:ElementName> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</rasd:InstanceID> + <rasd:ResourceType>3</rasd:ResourceType> + <rasd:VirtualQuantity>8</rasd:VirtualQuantity> + </Item> + <Item configuration="1CPU-512MB"> + <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits> + <rasd:Description>Memory Size</rasd:Description> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">512 MB of memory</rasd:ElementName> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</rasd:InstanceID> + <rasd:ResourceType>4</rasd:ResourceType> + <rasd:VirtualQuantity>512</rasd:VirtualQuantity> + <rasd:Reservation>512</rasd:Reservation> + </Item> + <Item configuration="4CPU-16GB"> + <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits> + <rasd:Description>Memory Size</rasd:Description> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">16 GB of memory</rasd:ElementName> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</rasd:InstanceID> + <rasd:ResourceType>4</rasd:ResourceType> + <rasd:VirtualQuantity>16384</rasd:VirtualQuantity> + <rasd:Reservation>16384</rasd:Reservation> + </Item> + <Item configuration="8CPU-32GB"> + <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits> + <rasd:Description>Memory Size</rasd:Description> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">32 GB of memory</rasd:ElementName> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</rasd:InstanceID> + <rasd:ResourceType>4</rasd:ResourceType> + <rasd:VirtualQuantity>32768</rasd:VirtualQuantity> + <rasd:Reservation>32768</rasd:Reservation> + </Item> + {%- else -%} + <Item> + <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits> + <rasd:Description>Number of virtual CPUs</rasd:Description> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1 virtual CPU</rasd:ElementName> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</rasd:InstanceID> + <rasd:ResourceType>3</rasd:ResourceType> + <rasd:VirtualQuantity>1</rasd:VirtualQuantity> + </Item> + <Item> + <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits> + <rasd:Description>Memory Size</rasd:Description> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4 GB of memory</rasd:ElementName> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</rasd:InstanceID> + <rasd:ResourceType>4</rasd:ResourceType> + <rasd:VirtualQuantity>4096</rasd:VirtualQuantity> + </Item> + {%- endif -%} + <Item> + <rasd:Address xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">0</rasd:Address> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">SCSI Controller 0 - VMware Paravirtual SCSI</rasd:ElementName> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</rasd:InstanceID> + <rasd:ResourceSubType>VirtualSCSI</rasd:ResourceSubType> + <rasd:ResourceType>6</rasd:ResourceType> + </Item> + <Item> + <rasd:AddressOnParent>0</rasd:AddressOnParent> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">disk0</rasd:ElementName> + <rasd:HostResource>ovf:/disk/vmdisk1</rasd:HostResource> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</rasd:InstanceID> + <rasd:Parent>3</rasd:Parent> + <rasd:ResourceType>17</rasd:ResourceType> + </Item> + <Item> + <rasd:Address>0</rasd:Address> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">IDE Controller 0</rasd:ElementName> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">5</rasd:InstanceID> + <rasd:ResourceType>5</rasd:ResourceType> + </Item> + <Item> + <rasd:AddressOnParent>0</rasd:AddressOnParent> + <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation> + <rasd:ElementName xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">CD/DVD Drive 1</rasd:ElementName> + <rasd:InstanceID xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">6</rasd:InstanceID> + <rasd:Parent>5</rasd:Parent> + <rasd:ResourceType>15</rasd:ResourceType> + </Item> + <ovf:Item> + <rasd:AddressOnParent>7</rasd:AddressOnParent> + <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> + <rasd:Connection>WAN</rasd:Connection> + <rasd:Description>NIC representing WAN</rasd:Description> + <rasd:ElementName>WAN</rasd:ElementName> + <rasd:InstanceID>7</rasd:InstanceID> + <rasd:ResourceSubType>vmxnet3</rasd:ResourceSubType> + <rasd:ResourceType>10</rasd:ResourceType> + </ovf:Item> + <ovf:Item> + <rasd:AddressOnParent>8</rasd:AddressOnParent> + <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> + <rasd:Connection>LAN</rasd:Connection> + <rasd:Description>NIC representing LAN</rasd:Description> + <rasd:ElementName>LAN</rasd:ElementName> + <rasd:InstanceID>8</rasd:InstanceID> + <rasd:ResourceSubType>vmxnet3</rasd:ResourceSubType> + <rasd:ResourceType>10</rasd:ResourceType> + </ovf:Item> + <vmw:Config ovf:required="false" vmw:key="cpuHotAddEnabled" vmw:value="true"/> + <vmw:Config ovf:required="false" vmw:key="memoryHotAddEnabled" vmw:value="true"/> + </VirtualHardwareSection> + </VirtualSystem> +</ovf:Envelope> diff --git a/roles/vmware/tests/inventory b/roles/vmware/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/vmware/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/vmware/tests/test.yml b/roles/vmware/tests/test.yml new file mode 100644 index 0000000..58552e3 --- /dev/null +++ b/roles/vmware/tests/test.yml @@ -0,0 +1,4 @@ +--- +- hosts: localhost + roles: + - vmware-ova diff --git a/roles/vmware/vars/main.yml b/roles/vmware/vars/main.yml new file mode 100644 index 0000000..598f592 --- /dev/null +++ b/roles/vmware/vars/main.yml @@ -0,0 +1,5 @@ +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_cert: /tmp/vyos_vmware_image.cert |