VMWARE rest colleciton

211 views
Skip to first unread message

shane cummins

unread,
Apr 20, 2023, 4:03:37 AM4/20/23
to Ansible Project
Hi all after recently changing over from AWX to AAP and changing from the community.VMware collection to VMware.rest collection.
I am running into some issues when deploying I am using the module,
VMware.vmware_rest.content_library_item_info:
deploying the VM from a template in the content library,
I am able to deploy the VM from the template without any problems,
using the below playbook.
but the issue I have is the newly deployed VM keeps the name of the,
name of the template the VM was created from and does not change the name at guest level,
just changes on the label of the VM.


---
- name: Deploy a VM from a library "Linux_Templates"
  hosts: localhost
  gather_facts: yes

  vars:
    hostname: "{{ lookup('env', 'VMWARE_HOST') }}"                 # vCenter Server hostname or IP address
    username: "{{ lookup('env', 'VMWARE_USER') }}"                 # vCenter Server username
    password: "{{ lookup('env', 'VMWARE_PASSWORD') }}"             # vCenter Server password
    vm_name: "{{new_name}}"                                        # Name to give to the new VM
    esxi_hostname: "esx node name"                      #ESX node name
    datastore: "datastore name"                                          # Name of the datastore to use
    cluster_ID: "cluster name"                                       # Cluster name
    folder_path: "folder path name"                                   # Name of the folder to place the new VM in
    content_library: "content library id"
    library_item: "item id"
    AD_Domain: "domain name"                                       # Domain name
    AD_Domain_alt: "alt domain name"                                   # Alternative domain name
    sudo_users: "{{sudo_user_add}}"                                # Sudo users to add to vm


  tasks:

    - name: get the list of items of the NFS library
      vmware.vmware_rest.content_library_item_info:
        vcenter_hostname: "{{hostname}}"
        vcenter_username: "{{username}}"
vcenter_password: "{{password}}"
        library_id: "{{content_library}}"
        library_item_id: "{{library_item}}"
      register: content_library_result
   
    - name: Create a new VM based on the template
      vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
        vcenter_hostname: "{{hostname}}"
        vcenter_username: "{{username}}"
vcenter_password: "{{password}}"
        name: "{{vm_name}}"
        vcenter_validate_certs: false
        library: "{{content_library}}"
        template_library_item: "{{library_item}}"  
        placement:
          cluster: "{{cluster_ID}}"
          folder:  "{{folder_path}}"
          #resource_pool:  "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources')}}"
        state: deploy
        powered_on: True
      register: my_new_vm

    - name: Pause for 1 minutes for server to boot up
      ansible.builtin.pause:
        seconds: 30

also when using the community collection i was able to just also add a task you use bash shell,
after VM was deployed in the same playbook like below
- name: "Join the VM to the Domain"
      shell: |  
         timeout 60s echo '{{vcenter_password}}' | sudo realm join --verbose exsample.COM -U 'user' --install=/ any help would be appreciated here

thanks
Shane

Dick Visser

unread,
Apr 20, 2023, 7:09:11 AM4/20/23
to ansible...@googlegroups.com
As you pointed out yourself, this seems to be a question related to the usage of https://github.com/ansible-collections/vmware.vmware_rest, so that would be the logical place to ask first, I would assume.
This list is more for general ansible questions rather than specific 3rd party content.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d737ed35-b86d-4f9e-b55c-b1ca2e486f33n%40googlegroups.com.

Rowe, Walter P. (Fed)

unread,
Apr 20, 2023, 8:10:23 AM4/20/23
to ansible...@googlegroups.com

  • Creates a library item in content library from a virtual machine. This {@term operation} creates a library item in content library whose content is a virtual machine template created from the source virtual machine, using the supplied create specification. The virtual machine template is stored in a newly created library item.
According to the documentation the vmware.vmware_rest.vcenter_vmtemplate_libraryitems module creates a library item in the content library. It does NOT create a new VM.

If you want to create a new VM I think you need to use the vmware.vmware_rest.vcenter_vm module with state 'clone' and source of the library item you want to use to create the new VM.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

Reply all
Reply to author
Forward
0 new messages