Skip to content

vmware_guest cannot clone across cluster boundaries #795

Open
@timblaktu

Description

@timblaktu
SUMMARY

I want to clone a template which resides in cluster A, to create a VM that resides in cluster B. Both clusters are in the same datacenter. It's not working.

In the below example:

  • "debian10" is the name of the template that resides in cluster A and is hosted on host 1.
  • cluster holds the desired cluster B for the new cloned machine
  • esxi_hostname holds the desired hostname for the new cloned machine
  • I understand that cluster and esxi_hostname are mutually-exclusive and should not both be specified.

The vmware_guest docs say "From version 2.8 onwards, absolute path to virtual machine or template can be used." But regardless of whether I specify cluster or esxi_hostname, and regardless of whether I specify just the template name (debian10) or the full path to the template (as obtained from vcommunity.vmware.vmware_vm_info, in my case this is /Engineering/vm/JenkinsCICD/debian10), I get this error:

13:32:53  TASK [Create New Machine in vSphere from Debian 10 Template, Power On for further Provisioning] ***
13:32:54  fatal: [localhost]: FAILED! => changed=false 
13:32:54    msg: 'Failed to create a virtual machine : Unable to access the virtual machine configuration: Unable to access file [bsienghost4:Local] debian10/debian10.vmtx'

To be clear, the VM gets cloned successfully, if:

  1. in this project, I use cluster: A and let it create the clone in the same cluster. (this is NOT the desired location, however)
  2. in another project I have which does the exact same thing, except that it can create the clone in the same cluster as the template, and so it specifies cluster with no problem.

For these reasons, I do not believe this issue to be related to permissions, and DO believe the issue to be with vmware_guest making some poor assumptions under the hood about clusters when cloning templates.

Here is the task in question:

    - name: Create New Machine in vSphere from Debian 10 Template, Power On for further Provisioning
      community.vmware.vmware_guest:
        hostname: "{{ vcenter_host }}"
        datacenter: "{{ datacenter }}"
        # cluster: "{{ cluster }}"
        esxi_hostname: "{{ esxi_hostname }}"
        folder: "{{ folder }}"
        # template: "debian10"
        template: "{{ all_templates_info.virtual_machines[template_indices|int].folder }}/{{ vmtemplate }}"
        # template: "{{ all_templates_info.virtual_machines[template_indices|int].moid }}"
        name: "{{ new_machine_name }}"
        state: powered-on
        annotation: "{{ new_machine_description }}"
        wait_for_ip_address: yes
      register: new_vm
      delegate_to: localhost

I have also tried looking up and specifying the uuid or moid for the template, but this doesn't work either. The docs, and the code that looks up a vm or template imply that template must be a name.

and here is the vvvverbose output from this task, in the case where I specified esxi_hostname and not cluster:

13:39:51  fatal: [localhost]: FAILED! => changed=false 
13:39:51    invocation:
13:39:51      module_args:
13:39:51        advanced_settings: []
13:39:51        annotation: Debian 10 (Buster) based software development VM created in vSphere for tim-black
13:39:51        cdrom: []
13:39:51        cluster: null
13:39:51        convert: null
13:39:51        customization:
13:39:51          autologon: null
13:39:51          autologoncount: null
13:39:51          dns_servers: null
13:39:51          dns_suffix: null
13:39:51          domain: null
13:39:51          domainadmin: null
13:39:51          domainadminpassword: null
13:39:51          existing_vm: null
13:39:51          fullname: null
13:39:51          hostname: null
13:39:51          hwclockUTC: null
13:39:51          joindomain: null
13:39:51          joinworkgroup: null
13:39:51          orgname: null
13:39:51          password: null
13:39:51          productid: null
13:39:51          runonce: null
13:39:51          timezone: null
13:39:51        customization_spec: null
13:39:51        customvalues: []
13:39:51        datacenter: Engineering
13:39:51        datastore: null
13:39:51        delete_from_inventory: false
13:39:51        disk: []
13:39:51        esxi_hostname: ********
13:39:51        folder: Personal Development Environments
13:39:51        force: false
13:39:51        guest_id: null
13:39:51        hardware:
13:39:51          boot_firmware: null
13:39:51          cpu_limit: null
13:39:51          cpu_reservation: null
13:39:51          hotadd_cpu: null
13:39:51          hotadd_memory: null
13:39:51          hotremove_cpu: null
13:39:51          max_connections: null
13:39:51          mem_limit: null
13:39:51          mem_reservation: null
13:39:51          memory_mb: null
13:39:51          memory_reservation_lock: null
13:39:51          nested_virt: null
13:39:51          num_cpu_cores_per_socket: null
13:39:51          num_cpus: null
13:39:51          scsi: null
13:39:51          version: null
13:39:51          virt_based_security: null
13:39:51        hostname: ********
13:39:51        is_template: false
13:39:51        linked_clone: false
13:39:51        name: tim-black-buster
13:39:51        name_match: first
13:39:51        networks: []
13:39:51        password: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
13:39:51        port: 443
13:39:51        proxy_host: null
13:39:51        proxy_port: null
13:39:51        resource_pool: null
13:39:51        snapshot_src: null
13:39:51        state: powered-on
13:39:51        state_change_timeout: 0
13:39:51        template: /Engineering/vm/JenkinsCICD/debian10
13:39:51        use_instance_uuid: false
13:39:51        username: ********
13:39:51        uuid: null
13:39:51        validate_certs: false
13:39:51        vapp_properties: []
13:39:51        wait_for_customization: false
13:39:51        wait_for_customization_timeout: 3600
13:39:51        wait_for_ip_address: true
13:39:51        wait_for_ip_address_timeout: 300
13:39:51    msg: 'Failed to create a virtual machine : Unable to access the virtual machine configuration: Unable to access file [bsienghost4:Local] debian10/debian10.vmtx'
ISSUE TYPE
  • Bug Report
COMPONENT NAME

vmware_guest, module_utils (get_vm_or_template)

ANSIBLE VERSION
13:39:35  + ansible --version
13:39:35  ansible 2.10.8
13:39:35    config file = /home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg
13:39:35    configured module search path = ['/home/jenkins/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
13:39:35    ansible python module location = /home/jenkins/.pyenv/versions/3.9.0/envs/Ansible-vsphere-d-SWOPS-869/lib/python3.9/site-packages/ansible
13:39:35    executable location = /home/jenkins/.pyenv/versions/Ansible-vsphere-d-SWOPS-869/bin/ansible
13:39:35    python version = 3.9.0 (default, Mar  9 2021, 12:09:04) [GCC 8.3.0]
CONFIGURATION
13:39:35  + ansible-config dump --only-changed
13:39:36  ANSIBLE_FORCE_COLOR(env: ANSIBLE_FORCE_COLOR) = True
13:39:36  ANSIBLE_PIPELINING(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = True
13:39:36  ANSIBLE_SSH_ARGS(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
13:39:36  COLLECTIONS_PATHS(env: ANSIBLE_COLLECTIONS_PATH) = ['/home/jenkins/.ansible/collections/Ansible-vsphere-d-SWOPS-869']
13:39:36  DEFAULT_CALLBACK_WHITELIST(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = ['yaml', 'timer', 'counter_enabled', 'junit', 'log_plays']
13:39:36  DEFAULT_FORKS(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = 20
13:39:36  DEFAULT_KEEP_REMOTE_FILES(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = True
13:39:36  DEFAULT_LOAD_CALLBACK_PLUGINS(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = True
13:39:36  DEFAULT_LOG_PATH(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = /home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.log
13:39:36  DEFAULT_MANAGED_STR(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = #Ansible managed by user {uid} on {host} from template file:
13:39:36  
13:39:36  DEFAULT_POLL_INTERVAL(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = 5
13:39:36  DEFAULT_REMOTE_USER(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = ansible
13:39:36  DEFAULT_ROLES_PATH(env: ANSIBLE_ROLES_PATH) = ['/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/roles', '/home/jenkins/.ansible/roles/Ansible-vsphere-d-SWOPS-869']
13:39:36  DEFAULT_STDOUT_CALLBACK(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = yaml
13:39:36  HOST_KEY_CHECKING(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = False
13:39:36  INTERPRETER_PYTHON(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = auto
13:39:36  RETRY_FILES_ENABLED(/home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg) = False
13:39:36  SHOW_CUSTOM_STATS(env: ANSIBLE_SHOW_CUSTOM_STATS) = True
OS / ENVIRONMENT

Debian 10.5 host, Debian 10.9.0 guests. Jenkins pipeline. Python 3.9.0

13:39:35  + ansible --version
13:39:35  ansible 2.10.8
13:39:35    config file = /home/jenkins/.jenkins/workspace/support-for-customizing-disk-and/ansible/projects/vsphere-development-environment/ansible.cfg
13:39:35    configured module search path = ['/home/jenkins/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
13:39:35    ansible python module location = /home/jenkins/.pyenv/versions/3.9.0/envs/Ansible-vsphere-d-SWOPS-869/lib/python3.9/site-packages/ansible
13:39:35    executable location = /home/jenkins/.pyenv/versions/Ansible-vsphere-d-SWOPS-869/bin/ansible
13:39:35    python version = 3.9.0 (default, Mar  9 2021, 12:09:04) [GCC 8.3.0]
13:39:35  + pip list
13:39:35  Package                            Version
13:39:35  ---------------------------------- ------------------
13:39:35  ansible                            2.10.0
13:39:35  ansible-base                       2.10.8
13:39:35  certifi                            2020.12.5
13:39:35  cffi                               1.14.5
13:39:35  chardet                            4.0.0
13:39:35  cryptography                       3.4.7
13:39:35  idna                               2.10
13:39:35  Jinja2                             2.11.3
13:39:35  junit-xml                          1.9
13:39:35  lxml                               4.6.3
13:39:35  MarkupSafe                         1.1.1
13:39:35  nsx-policy-python-sdk              3.0.2.0.0.16837625
13:39:35  nsx-python-sdk                     3.0.2.0.0.16837625
13:39:35  nsx-vmc-aws-integration-python-sdk 3.0.2.0.0.16837625
13:39:35  nsx-vmc-policy-python-sdk          3.0.2.0.0.16837625
13:39:35  packaging                          20.9
13:39:35  pip                                21.0.1
13:39:35  pycparser                          2.20
13:39:35  pyOpenSSL                          20.0.1
13:39:35  pyparsing                          2.4.7
13:39:35  pyvmomi                            7.0.1
13:39:35  PyYAML                             5.4.1
13:39:35  requests                           2.25.1
13:39:35  setuptools                         49.2.1
13:39:35  six                                1.15.0
13:39:35  suds-jurko                         0.6
13:39:35  urllib3                            1.26.4
13:39:35  vapi-client-bindings               3.5.0
13:39:35  vapi-common-client                 2.19.0
13:39:35  vapi-runtime                       2.19.0
13:39:35  vmc-client-bindings                1.29.0
13:39:35  vmc-draas-client-bindings          1.13.0
13:39:35  vSphere-Automation-SDK             1.39.0
STEPS TO REPRODUCE

see SUMMARY.

EXPECTED RESULTS

I expect this vmware_guest task to be able to clone template in cluster A onto a host on another cluster B.

ACTUAL RESULTS

See SUMMARY.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions