Housekeeping;Provision node templates;Add vApp properties
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Danny Bessems 2022-07-28 23:22:41 +02:00
parent 7440d5824c
commit 8e680c45be
4 changed files with 125 additions and 6 deletions

View File

@ -29,9 +29,10 @@
- name: Assign vApp properties to dictionary - name: Assign vApp properties to dictionary
ansible.builtin.set_fact: ansible.builtin.set_fact:
vapp: >- vapp: >-
{{ vapp | default({}) | {{ vapp | default({}) | combine({
combine({((item.values() | list)[0].values() | list)[0]: ((item.values() | list)[0].values() | list)[0]:
((item.values() | list)[0].values() | list)[1]}) ((item.values() | list)[0].values() | list)[1]})
}} }}
loop: "{{ property_section.matches }}" loop: "{{ property_section.matches }}"
no_log: true loop_control:
label: "{{ ((item.values() | list)[0].values() | list)[0] }}"

View File

@ -0,0 +1,93 @@
- block:
- name: Gather hypervisor details
ansible.builtin.shell:
cmd: govc ls -L {{ item.moref }} | awk -F/ '{print ${{ item.part }}}'
environment:
GOVC_INSECURE: '1'
GOVC_URL: "{{ vapp['hv.fqdn'] }}"
GOVC_USERNAME: "{{ vapp['hv.username'] }}"
GOVC_PASSWORD: "{{ vapp['hv.password'] }}"
register: govc_inventory
loop:
- attribute: cluster
moref: >-
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
jq -r '.[] | select(.Name == "runtime").Val.Host | .Type + ":" + .Value')
part: (NF-1)
- attribute: datacenter
moref: VirtualMachine:{{ moref_id }}
part: 2
- attribute: datastore
moref: >-
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
jq -r '.[] | select(.Name == "datastore").Val.ManagedObjectReference | .[].Type + ":" + .[].Value')
part: NF
- attribute: folder
moref: >-
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
jq -r '.[] | select(.Name == "parent").Val | .Type + ":" + .Value')
part: 0
# - attribute: host
# moref: >-
# $(govc object.collect -json VirtualMachine:{{ moref_id }} | \
# jq -r '.[] | select(.Name == "runtime").Val.Host | .Type + ":" + .Value')
# part: NF
- attribute: network
moref: >-
$(govc object.collect -json VirtualMachine:{{ moref_id }} | \
jq -r '.[] | select(.Name == "network").Val.ManagedObjectReference | .[].Type + ":" + .[].Value')
part: NF
loop_control:
label: "{{ item.attribute }}"
- name: Store hypervisor details in dictionary
ansible.builtin.set_fact:
vcenter_info: "{{ vcenter_info | default({}) | combine({ item.item.attribute : item.stdout }) }}"
loop: "{{ govc_inventory.results }}"
loop_control:
label: "{{ item.item.attribute }}"
- block:
- name: Parse OVA files for network mappings
ansible.builtin.shell:
cmd: govc import.spec -json {{ item }}
environment:
GOVC_INSECURE: '1'
GOVC_URL: "{{ vapp['hv.fqdn'] }}"
GOVC_USERNAME: "{{ vapp['hv.username'] }}"
GOVC_PASSWORD: "{{ vapp['hv.password'] }}"
register: ova_spec
with_fileglob: /opt/workloadcluster/node-templates/*.ova
- name: Deploy OVA templates on hypervisor
community.vmware.vmware_ovf_deploy:
hostname: "{{ vapp['hv.fqdn'] }}"
validate_certs: no
username: "{{ vapp['hv.username'] }}"
password: "{{ vapp['hv.password'] }}"
datacenter: "{{ vcenter_info.datacenter }}"
cluster: "{{ vcenter_info.cluster }}"
datastore: "{{ vcenter_info.datastore }}"
folder: "{{ vcenter_info.folder }}"
networks: "{u'{{ ova_spec.results[index].stdout | from_json | json_query('NetworkMappings[0].Name') }}':u'{{ vcenter_info.network }}'}"
power_on: false
ovf: "{{ item }}"
register: ova_deploy
with_fileglob: /opt/workloadcluster/node-templates/*.ova
loop_control:
index_var: index
- name: Mark deployed VM's as templates
community.vmware.vmware_guest:
hostname: "{{ vapp['hv.fqdn'] }}"
validate_certs: no
username: "{{ vapp['hv.username'] }}"
password: "{{ vapp['hv.password'] }}"
datacenter: "{{ vcenter_info.datacenter }}"
name: "{{ item.instance.hw_name }}"
is_template: yes
loop: "{{ ova_deploy.results }}"
loop_control:
label: "{{ item.instance.moid }}"

View File

@ -131,8 +131,6 @@ dependencies:
# - quay.io/skopeo/stable:v1.8.0 # - quay.io/skopeo/stable:v1.8.0
static_binaries: static_binaries:
- filename: tea
url: https://dl.gitea.io/tea/0.8.0/tea-0.8.0-linux-amd64
- filename: govc - filename: govc
url: https://github.com/vmware/govmomi/releases/download/v0.29.0/govc_Linux_x86_64.tar.gz url: https://github.com/vmware/govmomi/releases/download/v0.29.0/govc_Linux_x86_64.tar.gz
archive: compressed archive: compressed

View File

@ -114,6 +114,33 @@ PropertyCategories:
Configurations: '*' Configurations: '*'
UserConfigurable: true UserConfigurable: true
- Name: 4) Hypervisor
ProductProperties:
- Key: hv.fqdn
Type: string(1..)
Label: vCenter Appliance FQDN*
Description: ''
DefaultValue: ''
Configurations: '*'
UserConfigurable: true
- Key: hv.username
Type: string(1..)
Label: User name ...*
Description: ''
DefaultValue: ''
Configurations: '*'
UserConfigurable: true
- Key: hv.password
Type: string(1..)
Label: Password ...*
Description: ''
DefaultValue: ''
Configurations: '*'
UserConfigurable: true
AdvancedOptions: AdvancedOptions:
- Key: appliance.name - Key: appliance.name
Value: "{{ appliance.name }}" Value: "{{ appliance.name }}"