Reference node template by inventory path
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		@@ -47,7 +47,7 @@
 | 
			
		||||
        resourcepool: "{{ vcenter_info.resourcepool }}"
 | 
			
		||||
        folder: "{{ vcenter_info.folder }}"
 | 
			
		||||
      cluster:
 | 
			
		||||
        nodetemplate: "{{ (components.clusterapi.workload.node_template.url | basename | split('.'))[:-1] | join('.') }}"
 | 
			
		||||
        nodetemplate: "{{ nodetemplate_inventorypath }}"
 | 
			
		||||
        publickey: "{{ vapp['guestinfo.rootsshkey'] }}"
 | 
			
		||||
        version: "{{ components.clusterapi.workload.version.k8s }}"
 | 
			
		||||
        vip: "{{ vapp['workloadcluster.vip'] }}"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,82 +1,68 @@
 | 
			
		||||
- block:
 | 
			
		||||
 | 
			
		||||
    - name: Check for existing templates on hypervisor
 | 
			
		||||
    - name: Check for existing template on hypervisor
 | 
			
		||||
      community.vmware.vmware_guest_info:
 | 
			
		||||
        name: "{{ (item | basename | split('.'))[:-1] | join('.') }}"
 | 
			
		||||
        name: "{{ (filename | basename | split('.'))[:-1] | join('.') }}"
 | 
			
		||||
      register: existing_ova
 | 
			
		||||
      loop: "{{ query('ansible.builtin.fileglob', '/opt/metacluster/node-templates/*.ova') | first }}"
 | 
			
		||||
      ignore_errors: yes
 | 
			
		||||
 | 
			
		||||
    - name: Parse OVA files for network mappings
 | 
			
		||||
    - 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 {{ item }}
 | 
			
		||||
            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
 | 
			
		||||
      when: existing_ova.results[index] is failed
 | 
			
		||||
      loop: "{{ query('ansible.builtin.fileglob', '/opt/metacluster/node-templates/*.ova') | first }}"
 | 
			
		||||
      loop_control:
 | 
			
		||||
        index_var: index
 | 
			
		||||
 | 
			
		||||
    - name: Deploy OVA templates on hypervisor
 | 
			
		||||
        - name: Deploy OVA template on hypervisor
 | 
			
		||||
          community.vmware.vmware_deploy_ovf:
 | 
			
		||||
            cluster: "{{ vcenter_info.cluster }}"
 | 
			
		||||
            datastore: "{{ vcenter_info.datastore }}"
 | 
			
		||||
        name: "{{ (item | basename | split('.'))[:-1] | join('.') }}"
 | 
			
		||||
        networks: "{u'{{ ova_spec.results[index].stdout | from_json | json_query('NetworkMapping[0].Name') }}':u'{{ vcenter_info.network }}'}"
 | 
			
		||||
            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: "{{ item }}"
 | 
			
		||||
            ovf: "{{ filename }}"
 | 
			
		||||
          register: ova_deploy
 | 
			
		||||
      when: existing_ova.results[index] is failed
 | 
			
		||||
      loop: "{{ query('ansible.builtin.fileglob', '/opt/metacluster/node-templates/*.ova') | first }}"
 | 
			
		||||
      loop_control:
 | 
			
		||||
        index_var: index
 | 
			
		||||
 | 
			
		||||
    - debug:
 | 
			
		||||
        msg: "{{ existing_ova.results | first }}"
 | 
			
		||||
    - debug:
 | 
			
		||||
        msg: "{{ ova_deploy.results | first }}"
 | 
			
		||||
 | 
			
		||||
        - name: Add additional placeholder disk
 | 
			
		||||
          community.vmware.vmware_guest_disk:
 | 
			
		||||
        name: "{{ item.instance.hw_name }}"
 | 
			
		||||
            name: "{{ ova_deploy.instance.hw_name }}"
 | 
			
		||||
            disk:
 | 
			
		||||
              - size: 1Gb
 | 
			
		||||
                scsi_controller: 1
 | 
			
		||||
                scsi_type: paravirtual
 | 
			
		||||
                unit_number: 0
 | 
			
		||||
      when: ova_deploy.results[index] is not skipped
 | 
			
		||||
      loop: "{{ ova_deploy.results }}"
 | 
			
		||||
      loop_control:
 | 
			
		||||
        index_var: index
 | 
			
		||||
        label: "{{ item.item }}"
 | 
			
		||||
 | 
			
		||||
        # Disabled to allow disks to be resized; at the cost of cloning speed
 | 
			
		||||
    # - name: Create snapshot on deployed VM's
 | 
			
		||||
        # - name: Create snapshot on deployed VM
 | 
			
		||||
        #   community.vmware.vmware_guest_snapshot:
 | 
			
		||||
    #     name: "{{ item.instance.hw_name }}"
 | 
			
		||||
        #     name: "{{ ova_deploy.instance.hw_name }}"
 | 
			
		||||
        #     state: present
 | 
			
		||||
        #     snapshot_name: "{{ ansible_date_time.iso8601_basic_short }}-base"
 | 
			
		||||
    #   when: ova_deploy.results[index] is not skipped
 | 
			
		||||
    #   loop: "{{ ova_deploy.results }}"
 | 
			
		||||
    #   loop_control:
 | 
			
		||||
    #     index_var: index
 | 
			
		||||
    #     label: "{{ item.item }}"
 | 
			
		||||
 | 
			
		||||
    - name: Mark deployed VM's as templates
 | 
			
		||||
        - name: Mark deployed VM as templates
 | 
			
		||||
          community.vmware.vmware_guest:
 | 
			
		||||
        name: "{{ item.instance.hw_name }}"
 | 
			
		||||
            name: "{{ ova_deploy.instance.hw_name }}"
 | 
			
		||||
            is_template: yes
 | 
			
		||||
      when: ova_deploy.results[index] is not skipped
 | 
			
		||||
      loop: "{{ ova_deploy.results }}"
 | 
			
		||||
      loop_control:
 | 
			
		||||
        index_var: index
 | 
			
		||||
        label: "{{ item.item }}"
 | 
			
		||||
 | 
			
		||||
        - 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'] }}"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,81 +1,68 @@
 | 
			
		||||
- block:
 | 
			
		||||
 | 
			
		||||
    - name: Check for existing templates on hypervisor
 | 
			
		||||
    - name: Check for existing template on hypervisor
 | 
			
		||||
      community.vmware.vmware_guest_info:
 | 
			
		||||
        name: "{{ (item | basename | split('.'))[:-1] | join('.') }}"
 | 
			
		||||
        name: "{{ (filename | basename | split('.'))[:-1] | join('.') }}"
 | 
			
		||||
      register: existing_ova
 | 
			
		||||
      loop: "{{ query('ansible.builtin.fileglob', '/opt/workloadcluster/node-templates/*.ova') | first }}"
 | 
			
		||||
      ignore_errors: yes
 | 
			
		||||
 | 
			
		||||
    - name: Parse OVA files for network mappings
 | 
			
		||||
    - 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 {{ item }}
 | 
			
		||||
            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
 | 
			
		||||
      when: existing_ova.results[index] is failed
 | 
			
		||||
      loop: "{{ query('ansible.builtin.fileglob', '/opt/workloadcluster/node-templates/*.ova') | first }}"
 | 
			
		||||
      loop_control:
 | 
			
		||||
        index_var: index
 | 
			
		||||
 | 
			
		||||
    - name: Deploy OVA templates on hypervisor
 | 
			
		||||
        - name: Deploy OVA template on hypervisor
 | 
			
		||||
          community.vmware.vmware_deploy_ovf:
 | 
			
		||||
            cluster: "{{ vcenter_info.cluster }}"
 | 
			
		||||
            datastore: "{{ vcenter_info.datastore }}"
 | 
			
		||||
        folder: "{{ vcenter_info.folder }}"
 | 
			
		||||
        name: "{{ (item | basename | split('.'))[:-1] | join('.') }}"
 | 
			
		||||
        networks: "{u'{{ ova_spec.results[index].stdout | from_json | json_query('NetworkMapping[0].Name') }}':u'{{ vcenter_info.network }}'}"
 | 
			
		||||
            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: "{{ item }}"
 | 
			
		||||
            ovf: "{{ filename }}"
 | 
			
		||||
          register: ova_deploy
 | 
			
		||||
      when: existing_ova.results[index] is failed
 | 
			
		||||
      loop: "{{ query('ansible.builtin.fileglob', '/opt/workloadcluster/node-templates/*.ova') | first }}"
 | 
			
		||||
      loop_control:
 | 
			
		||||
        index_var: index
 | 
			
		||||
 | 
			
		||||
    - name: Add vApp properties on deployed VM's
 | 
			
		||||
      ansible.builtin.shell:
 | 
			
		||||
        cmd: >-
 | 
			
		||||
          npp-prepper \
 | 
			
		||||
            --server "{{ vapp['hv.fqdn'] }}" \
 | 
			
		||||
            --username "{{ vapp['hv.username'] }}" \
 | 
			
		||||
            --password "{{ vapp['hv.password'] }}" \
 | 
			
		||||
            vm \
 | 
			
		||||
            --datacenter "{{ vcenter_info.datacenter }}" \
 | 
			
		||||
            --portgroup "{{ vcenter_info.network }}" \
 | 
			
		||||
            --name "{{ item.instance.hw_name }}"
 | 
			
		||||
      when: existing_ova.results[index] is failed
 | 
			
		||||
      loop: "{{ ova_deploy.results }}"
 | 
			
		||||
      loop_control:
 | 
			
		||||
        index_var: index
 | 
			
		||||
        label: "{{ item.item }}"
 | 
			
		||||
        - 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
 | 
			
		||||
 | 
			
		||||
    - name: Create snapshot on deployed VM's
 | 
			
		||||
      community.vmware.vmware_guest_snapshot:
 | 
			
		||||
        folder: "{{ vcenter_info.folder }}"
 | 
			
		||||
        name: "{{ item.instance.hw_name }}"
 | 
			
		||||
        state: present
 | 
			
		||||
        snapshot_name: "{{ ansible_date_time.iso8601_basic_short }}-base"
 | 
			
		||||
      when: ova_deploy.results[index] is not skipped
 | 
			
		||||
      loop: "{{ ova_deploy.results }}"
 | 
			
		||||
      loop_control:
 | 
			
		||||
        index_var: index
 | 
			
		||||
        label: "{{ item.item }}"
 | 
			
		||||
        # 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's as templates
 | 
			
		||||
        - name: Mark deployed VM as templates
 | 
			
		||||
          community.vmware.vmware_guest:
 | 
			
		||||
        name: "{{ item.instance.hw_name }}"
 | 
			
		||||
            name: "{{ ova_deploy.instance.hw_name }}"
 | 
			
		||||
            is_template: yes
 | 
			
		||||
      when: ova_deploy.results[index] is not skipped
 | 
			
		||||
      loop: "{{ ova_deploy.results }}"
 | 
			
		||||
      loop_control:
 | 
			
		||||
        index_var: index
 | 
			
		||||
        label: "{{ item.item }}"
 | 
			
		||||
 | 
			
		||||
        - 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'] }}"
 | 
			
		||||
@@ -83,3 +70,4 @@
 | 
			
		||||
      username: "{{ vapp['hv.username'] }}"
 | 
			
		||||
      password: "{{ vapp['hv.password'] }}"
 | 
			
		||||
      datacenter: "{{ vcenter_info.datacenter }}"
 | 
			
		||||
      folder: "{{ vcenter_info.folder }}"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user