ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
349 stars 341 forks source link

Clone VM from linux template with cloud init #1834

Open mohammad0012 opened 1 year ago

mohammad0012 commented 1 year ago

Hello, I cant find Ansible module to clone a new VM from template and using cloud init. I am trying to use this module https://github.com/ansible-collections/community.vmware/blob/fd203158eb8d67e4bf218b33fe98fd1afa922072/docs/community.vmware.vmware_guest_module.rst#L4

ihumster commented 1 year ago

You can try using module vcenter_vm_guest_customization_module from vmware.vmware_rest. VmGuestCustomizationSetSpec Data Structure support cloud-init spec.

hideakihal commented 11 months ago

Hi. I was able to set the metadata for cloud-init by writing as follows.

- name:  Set the metadata and userdata for the virtual machine
  community.vmware.vmware_guest:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    validate_certs: no
    state: present
    name: "{{ vm_name }}"
    advanced_settings:
      - key: guestinfo.metadata
        value: "{{ lookup('template', 'metadata.j2') | b64encode }}"
      - key: guestinfo.metadata.encoding
        value: base64
      - key: guestinfo.userdata
        value: "{{ lookup('template', 'userdata.j2') | b64encode }}"
      - key: guestinfo.userdata.encoding
        value: base64
  delegate_to: localhost
j-random-geek commented 1 month ago

@hideakihal What does your metadata.j2 template look like? What format of data is it producing (yaml or json)?

Been bashing my head against this for too many hours... it's incredibly frustrating.