Housekeeping;Provision node templates;Add vApp properties
	
		
			
	
		
	
	
		
	
		
			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:
		| @@ -29,9 +29,10 @@ | ||||
| - name: Assign vApp properties to dictionary | ||||
|   ansible.builtin.set_fact: | ||||
|     vapp: >- | ||||
|       {{ vapp | default({}) | | ||||
|       combine({((item.values() | list)[0].values() | list)[0]: | ||||
|       ((item.values() | list)[0].values() | list)[1]}) | ||||
|       {{ vapp | default({}) | combine({ | ||||
|         ((item.values() | list)[0].values() | list)[0]: | ||||
|         ((item.values() | list)[0].values() | list)[1]}) | ||||
|       }} | ||||
|   loop: "{{ property_section.matches }}" | ||||
|   no_log: true | ||||
|   loop_control: | ||||
|     label: "{{ ((item.values() | list)[0].values() | list)[0] }}" | ||||
|   | ||||
| @@ -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 }}" | ||||
		Reference in New Issue
	
	Block a user