74 lines
2.8 KiB
YAML
74 lines
2.8 KiB
YAML
- block:
|
|
|
|
- name: Check for existing template on hypervisor
|
|
community.vmware.vmware_guest_info:
|
|
name: "{{ (filename | basename | split('.'))[:-1] | join('.') }}"
|
|
register: existing_ova
|
|
ignore_errors: yes
|
|
|
|
- name: Store inventory path of existing template
|
|
ansible.builtin.set_fact:
|
|
nodetemplate_inventorypath: "{{ existing_ova.instance.hw_folder ~ '/' ~ existing_ova.instance.hw_name }}"
|
|
when: existing_ova is not failed
|
|
|
|
- block:
|
|
|
|
- name: Parse OVA file for network mappings
|
|
ansible.builtin.shell:
|
|
cmd: govc import.spec -json {{ filename }}
|
|
environment:
|
|
GOVC_INSECURE: '1'
|
|
GOVC_URL: "{{ vapp['hv.fqdn'] }}"
|
|
GOVC_USERNAME: "{{ vapp['hv.username'] }}"
|
|
GOVC_PASSWORD: "{{ vapp['hv.password'] }}"
|
|
register: ova_spec
|
|
|
|
- name: Deploy OVA template on hypervisor
|
|
community.vmware.vmware_deploy_ovf:
|
|
cluster: "{{ vcenter_info.cluster }}"
|
|
datastore: "{{ vcenter_info.datastore }}"
|
|
name: "{{ (filename | basename | split('.'))[:-1] | join('.') }}"
|
|
networks: "{u'{{ ova_spec.stdout | from_json | json_query('NetworkMapping[0].Name') }}':u'{{ vcenter_info.network }}'}"
|
|
allow_duplicates: no
|
|
power_on: false
|
|
ovf: "{{ filename }}"
|
|
register: ova_deploy
|
|
|
|
- name: Add additional placeholder disk
|
|
community.vmware.vmware_guest_disk:
|
|
name: "{{ ova_deploy.instance.hw_name }}"
|
|
disk:
|
|
- size: 1Gb
|
|
scsi_controller: 1
|
|
scsi_type: paravirtual
|
|
unit_number: 0
|
|
|
|
# Disabled to allow disks to be resized; at the cost of cloning speed
|
|
# - name: Create snapshot on deployed VM
|
|
# community.vmware.vmware_guest_snapshot:
|
|
# name: "{{ ova_deploy.instance.hw_name }}"
|
|
# state: present
|
|
# snapshot_name: "{{ ansible_date_time.iso8601_basic_short }}-base"
|
|
|
|
- name: Mark deployed VM as templates
|
|
community.vmware.vmware_guest:
|
|
name: "{{ ova_deploy.instance.hw_name }}"
|
|
is_template: yes
|
|
|
|
- name: Store inventory path of deployed template
|
|
ansible.builtin.set_fact:
|
|
nodetemplate_inventorypath: "{{ ova_deploy.instance.hw_folder ~ '/' ~ ova_deploy.instance.hw_name }}"
|
|
|
|
when: existing_ova is failed
|
|
|
|
vars:
|
|
filename: "{{ query('ansible.builtin.fileglob', '/opt/metacluster/node-templates/*.ova') | first }}"
|
|
module_defaults:
|
|
group/vmware:
|
|
hostname: "{{ vapp['hv.fqdn'] }}"
|
|
validate_certs: no
|
|
username: "{{ vapp['hv.username'] }}"
|
|
password: "{{ vapp['hv.password'] }}"
|
|
datacenter: "{{ vcenter_info.datacenter }}"
|
|
folder: "{{ vcenter_info.folder }}"
|