feat: Remove node-template hypervisor upload logic (treat as prerequisite instead)
This commit is contained in:
		| @@ -1,73 +0,0 @@ | ||||
| - 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: 1Mb | ||||
|                 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/workloadcluster/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 }}" | ||||
| @@ -0,0 +1,33 @@ | ||||
| - block: | ||||
|  | ||||
|   - name: Check for existing template | ||||
|     community.vmware.vmware_guest_info: | ||||
|       name: "{{ vapp['workloadcluster.nodetemplate'] }}" | ||||
|       hostname: "{{ vapp['hv.fqdn'] }}" | ||||
|       validate_certs: false | ||||
|       username: "{{ vapp['hv.username'] }}" | ||||
|       password: "{{ vapp['hv.password'] }}" | ||||
|       datacenter: "{{ vcenter_info.datacenter }}" | ||||
|       folder: "{{ vcenter_info.folder }}" | ||||
|     register: nodetemplate | ||||
|     until: | ||||
|       - nodetemplate is not failed | ||||
|     retries: 600 | ||||
|     delay: 30 | ||||
|     #wait for 5 hr. | ||||
|     vars: | ||||
|       color_reset: "\e[0m" | ||||
|       ansible_callback_diy_runner_retry_msg: >- | ||||
|         {%- set result = ansible_callback_diy.result.output -%} | ||||
|         {%- set retries_left = result.retries - result.attempts -%} | ||||
|         TEMPLATE '{{ vapp['workloadcluster.nodetemplate'] }}' NOT FOUND; PLEASE UPLOAD MANUALLY -- ({{ retries_left }} retries left) | ||||
|       ansible_callback_diy_runner_retry_msg_color: bright yellow | ||||
|  | ||||
|   - name: Store inventory path of existing template | ||||
|     ansible.builtin.set_fact: | ||||
|       nodetemplate_inventorypath: "{{ nodetemplate.instance.hw_folder ~ '/' ~ nodetemplate.instance.hw_name }}" | ||||
|  | ||||
|   rescue: | ||||
|   - name: CRITICAL ERROR | ||||
|     ansible.builtin.fail: | ||||
|       msg: Required node-template is not available; cannot continue | ||||
| @@ -1,73 +0,0 @@ | ||||
| - 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 }}" | ||||
		Reference in New Issue
	
	Block a user