Add vApp xml parse logic
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Danny Bessems 2021-06-09 22:11:06 +02:00
parent b33280b443
commit c0953acefe
5 changed files with 35 additions and 42 deletions

View File

@ -0,0 +1,7 @@
- name: Create netplan configuration file
ansible.builtin.template:
src: netplan.j2
dest: /etc/netplan/00-installer-config.yaml
- name: Apply netplan configuration
ansible.builtin.shell:
cmd: netplan apply

View File

@ -0,0 +1,10 @@
network:
version: 2
ethernets:
ens192:
addresses:
- {{ ovfproperties['guestinfo.ipaddress'] }}/{{ ovfproperties['guestinfo.prefixlength']}}
gateway4: {{ ovfproperties['guestinfo.gateway'] }}
nameservers:
addresses:
- {{ ovfproperties['guestinfo.dnsserver'] }}

View File

@ -1,44 +1,20 @@
- name: Store current vApp configuration
- name: Store current ovfEnvironment
ansible.builtin.shell:
cmd: vmtoolsd --cmd "info-get guestinfo.ovfEnv"
register: ovfenv
- name: DEBUG variable contents
ansible.builtin.debug:
ovfenv
- name: Parse XML into variables
- name: Parse XML for vApp properties
community.general.xml:
xmlstring: "{{ ovfEnv }}"
xmlstring: "{{ ovfenv.stdout }}"
namespaces:
oe: http://schemas.dmtf.org/ovf/environment/1
xpath: /Environment/PropertySection/Property
content: oe:key
# <?xml version="1.0" encoding="UTF-8"?>
# <Environment
# xmlns="http://schemas.dmtf.org/ovf/environment/1"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
# xmlns:oe="http://schemas.dmtf.org/ovf/environment/1"
# xmlns:ve="http://www.vmware.com/schema/ovfenv"
# oe:id=""
# ve:vCenterId="vm-1171">
# <PlatformSection>
# <Kind>VMware ESXi</Kind>
# <Version>7.0.1</Version>
# <Vendor>VMware, Inc.</Vendor>
# <Locale>en</Locale>
# </PlatformSection>
# <PropertySection>
# <Property oe:key="deployment.type" oe:value="ubuntu-small"/>
# <Property oe:key="guestinfo.dnsserver" oe:value="1.1.1.1"/>
# <Property oe:key="guestinfo.gateway" oe:value="10.0.0.1"/>
# <Property oe:key="guestinfo.hostname" oe:value="SRV01"/>
# <Property oe:key="guestinfo.ipaddress" oe:value="10.0.0.84"/>
# <Property oe:key="guestinfo.ntpserver" oe:value="0.pool.ntp.org,1.pool.ntp.org,2.pool.ntp.org"/>
# <Property oe:key="guestinfo.prefixlength" oe:value="24"/>
# <Property oe:key="guestinfo.rootpw" oe:value=""/>
# </PropertySection>
# <ve:EthernetAdapterSection>
# <ve:Adapter ve:mac="00:50:56:8a:09:08" ve:network="Staging" ve:unitNumber="7"/>
# </ve:EthernetAdapterSection>
# </Environment>
ns: http://schemas.dmtf.org/ovf/environment/1
xpath: /ns:Environment/ns:PropertySection/ns:Property
content: attribute
register: ovfenv
- name: Assign vApp properties to dictionary
ansible.builtin.set_fact:
ovfproperties: >-
{{ ovfproperties | default({}) |
combine({((item.values() | list)[0].values() | list)[0]:
((item.values() | list)[0].values() | list)[1]})
}}
loop: "{{ ovfenv.matches }}"

View File

@ -1,3 +1,4 @@
#!/bin/bash
# FOO
# Apply firstboot configuration w/ ansible
ansible-playbook /opt/firstboot/ansible/playbook.yml

View File

@ -3,9 +3,8 @@ packages:
- python3-pip
- python3-setuptools
- python3-wheel
# (libxml2-utils) Dependency for xmllint
- libxml2-utils
pip_packages:
- pip
- ansible-core
- lxml