Open walterrowe opened 3 years ago
Files identified in the description:
plugins/modules/vmware_guest_cross_vc_clone.py
](https://github.com/['ansible-collections/amazon.aws', 'ansible-collections/community.aws', 'ansible-collections/community.vmware']/blob/main/plugins/modules/vmware_guest_cross_vc_clone.py)If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
cc @Akasurde @Tomorrow9 @anusha94 @goneri @lparkes @pgbidkar @warthog9 click here for bot help
cc @anusha94
I tested cloning within the same vcenter environment with success. Different vmware systems in my environment have firewalls between them. Next step is to have firewall team monitor logs while testing cross-vcenter cloning to see if this is a firewall issue masquerading as a resource pool privilege error.
@walterrowe Thanks for the information. Please keep us posted.
needs_info
Now getting an error regarding CrossVCCloneManager: no attribute vm_uuid
. I am attempting to clone a template from one vCenter to another by template name.
Error still persists.
ansible playbook
---
## https://docs.ansible.com/ansible/2.10/collections/community/vmware/vmware_guest_cross_vc_clone_module.html
##
## clone templates from esx_vcloud to esx_gburg and esx_boulder
##
## ansible-playbook clone-esx-templates.yml -e @clonevars.yml
## clonevars.yml vars file should provide username / password vars
##
- name: clone esx templates to production
hosts: localhost
gather_facts: no
become: no
vars:
sites: [ esx_gburg, esx_boulder ]
templates: [ centos7, redhat7, redhat8, debian10, ubuntu20, windows2016, windows2019 ]
vars_files:
- esx-vars.yml
tasks:
- name: clone templates from esx_vcloud to esx_gburg
delegate_to: localhost
timeout: 3000
community.vmware.vmware_guest_cross_vc_clone:
# template source
hostname: "{{ vcenter['esx_vcloud'].vc }}"
username: "{{ username }}"
password: "{{ password }}"
validate_certs: no
name: "{{ item.1 }}"
# template destination
destination_vcenter: "{{ vcenter[item.0].vc }}"
destination_vcenter_username: "{{ username }}"
destination_vcenter_password: "{{ password }}"
destination_vcenter_validate_certs: no
destination_datastore: "automation"
destination_vm_folder: "templates"
destination_host: "{{ vcenter[item.0].vh }}"
destination_vm_name: "{{ item.1 }}_wpr"
state: present
# maps item.0 to site name, item.1 to template name
loop: "{{ sites | product(templates) | list }}"
register: clone_result
extracted error message
ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py", line 257, in sanitize_params
AttributeError: 'CrossVCCloneManager' object has no attribute 'vm_uuid'
full traceback
% ansible-playbook -vvv clone-esx-templates.yml -e @clonevars-wpr.yml
ansible-playbook [core 2.11.2]
config file = None
configured module search path = ['/Users/wrowe/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/Cellar/ansible/4.1.0/libexec/lib/python3.9/site-packages/ansible
ansible collection location = /Users/wrowe/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-playbook
python version = 3.9.5 (default, May 4 2021, 03:36:27) [Clang 12.0.0 (clang-1200.0.32.29)]
jinja version = 3.0.1
libyaml = True
No config file found; using defaults
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match
'all'
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: clone-esx-templates.yml **************************************************************************************
1 plays in clone-esx-templates.yml
Read vars_file 'esx-vars.yml'
Read vars_file 'esx-vars.yml'
Read vars_file 'esx-vars.yml'
PLAY [clone esx templates to production] *******************************************************************************
Read vars_file 'esx-vars.yml'
META: ran handlers
Read vars_file 'esx-vars.yml'
Read vars_file 'esx-vars.yml'
TASK [clone templates from esx_vcloud to esx_gburg] ********************************************************************
task path: /Users/wrowe/git-repos/image-factory/clone-esx-templates.yml:20
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: wrowe
<localhost> EXEC /bin/sh -c 'echo ~wrowe && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/wrowe/.ansible/tmp `"&& mkdir "` echo /Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928 `" && echo ansible-tmp-1624564814.1019-46580-153040304005928="` echo /Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928 `" ) && sleep 0'
Using module file /Users/wrowe/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py
<localhost> PUT /Users/wrowe/.ansible/tmp/ansible-local-46577ymw5jgdu/tmpw_7zbddg TO /Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928/AnsiballZ_vmware_guest_cross_vc_clone.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928/ /Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928/AnsiballZ_vmware_guest_cross_vc_clone.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/local/Cellar/ansible/4.1.0/libexec/bin/python3.9 /Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928/AnsiballZ_vmware_guest_cross_vc_clone.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928/ > /dev/null 2>&1 && sleep 0'
<localhost> EXEC /bin/sh -c 'echo ~wrowe && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928/AnsiballZ_vmware_guest_cross_vc_clone.py", line 100, in <module>
_ansiballz_main()
File "/Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928/AnsiballZ_vmware_guest_cross_vc_clone.py", line 92, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928/AnsiballZ_vmware_guest_cross_vc_clone.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_guest_cross_vc_clone', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_guest_cross_vc_clone', _modlib_path=modlib_path),
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 210, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_dvmlutu_/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py", line 388, in <module>
File "/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_dvmlutu_/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py", line 377, in main
File "/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_dvmlutu_/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py", line 257, in sanitize_params
AttributeError: 'CrossVCCloneManager' object has no attribute 'vm_uuid'
failed: [localhost -> localhost] (item=['esx_gburg', 'redhat7']) => {
"ansible_loop_var": "item",
"changed": false,
"item": [
"esx_gburg",
"redhat7"
],
"module_stderr": "Traceback (most recent call last):\n File \"/Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928/AnsiballZ_vmware_guest_cross_vc_clone.py\", line 100, in <module>\n _ansiballz_main()\n File \"/Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928/AnsiballZ_vmware_guest_cross_vc_clone.py\", line 92, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/Users/wrowe/.ansible/tmp/ansible-tmp-1624564814.1019-46580-153040304005928/AnsiballZ_vmware_guest_cross_vc_clone.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_guest_cross_vc_clone', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_guest_cross_vc_clone', _modlib_path=modlib_path),\n File \"/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 210, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_dvmlutu_/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py\", line 388, in <module>\n File \"/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_dvmlutu_/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py\", line 377, in main\n File \"/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_dvmlutu_/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py\", line 257, in sanitize_params\nAttributeError: 'CrossVCCloneManager' object has no attribute 'vm_uuid'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/wrowe/.ansible/tmp `"&& mkdir "` echo /Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278 `" && echo ansible-tmp-1624564815.124944-46580-77011623577278="` echo /Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278 `" ) && sleep 0'
Using module file /Users/wrowe/.ansible/collections/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py
<localhost> PUT /Users/wrowe/.ansible/tmp/ansible-local-46577ymw5jgdu/tmp10ex60_6 TO /Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278/AnsiballZ_vmware_guest_cross_vc_clone.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278/ /Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278/AnsiballZ_vmware_guest_cross_vc_clone.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/local/Cellar/ansible/4.1.0/libexec/bin/python3.9 /Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278/AnsiballZ_vmware_guest_cross_vc_clone.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278/AnsiballZ_vmware_guest_cross_vc_clone.py", line 100, in <module>
_ansiballz_main()
File "/Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278/AnsiballZ_vmware_guest_cross_vc_clone.py", line 92, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278/AnsiballZ_vmware_guest_cross_vc_clone.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_guest_cross_vc_clone', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_guest_cross_vc_clone', _modlib_path=modlib_path),
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 210, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_vrwztvx2/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py", line 388, in <module>
File "/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_vrwztvx2/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py", line 377, in main
File "/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_vrwztvx2/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py", line 257, in sanitize_params
AttributeError: 'CrossVCCloneManager' object has no attribute 'vm_uuid'
failed: [localhost -> localhost] (item=['esx_boulder', 'redhat7']) => {
"ansible_loop_var": "item",
"changed": false,
"item": [
"esx_boulder",
"redhat7"
],
"module_stderr": "Traceback (most recent call last):\n File \"/Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278/AnsiballZ_vmware_guest_cross_vc_clone.py\", line 100, in <module>\n _ansiballz_main()\n File \"/Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278/AnsiballZ_vmware_guest_cross_vc_clone.py\", line 92, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/Users/wrowe/.ansible/tmp/ansible-tmp-1624564815.124944-46580-77011623577278/AnsiballZ_vmware_guest_cross_vc_clone.py\", line 40, in invoke_module\n runpy.run_module(mod_name='ansible_collections.community.vmware.plugins.modules.vmware_guest_cross_vc_clone', init_globals=dict(_module_fqn='ansible_collections.community.vmware.plugins.modules.vmware_guest_cross_vc_clone', _modlib_path=modlib_path),\n File \"/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 210, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_vrwztvx2/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py\", line 388, in <module>\n File \"/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_vrwztvx2/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py\", line 377, in main\n File \"/var/folders/bx/rk3w_v413qs0hxjmb6pcr7r400184g/T/ansible_community.vmware.vmware_guest_cross_vc_clone_payload_vrwztvx2/ansible_community.vmware.vmware_guest_cross_vc_clone_payload.zip/ansible_collections/community/vmware/plugins/modules/vmware_guest_cross_vc_clone.py\", line 257, in sanitize_params\nAttributeError: 'CrossVCCloneManager' object has no attribute 'vm_uuid'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
PLAY RECAP *************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Link to line 257:
I think this method of checking for which parameter was provided doesn't work. The purpose of this line is merely to provide an argument to the error message when the clone source is not found.
@Akasurde .. please review this .. I believe this is a bug but unsure how to fix it.
production code:
self.vm_obj = self.get_vm()
if self.vm_obj is None:
vm_id = self.vm_uuid or self.vm_name or self.moid
self.module.fail_json(msg="Failed to find the VM/template with %s" % vm_id)
I tried the following and it also failed to define a value for vm_id even though I clearly specify name in playbook.
self.vm_obj = self.get_vm()
if self.vm_obj is None:
vm_id = None
if hasattr(self,'vm_uuid'):
vm_id = self.vm_uuid
elif hasattr(self,'vm_name'):
vm_id = self.vm_name
elif hasattr(self,'moid'):
vm_id = self.moid
self.module.fail_json(msg="Failed to find the VM/template with %s" % vm_id)
This ends up with a value of None for vm_id.
The line vm_id = self.vm_uuid or self.vm_name or self.moid
does not produce the desired behavior in current Python. It errors out with no attribute vm_uuid
.
Following up ... this appears to work ...
self.vm_obj = self.get_vm()
if self.vm_obj is None:
# vm_id = self.vm_uuid or self.vm_name or self.moid
vm_id = None
if 'uuid' in self.params and self.params['uuid'] is not None:
vm_id = self.params['uuid']
elif 'name' in self.params and self.params['name'] is not None:
vm_id = self.params['name']
elif 'moid' in self.params and self.params['moid'] is not None:
vm_id = self.params['moid']
self.module.fail_json(msg="Failed to find the VM/template with %s" % vm_id)
However, I am back to the original problem with permissions. I am cloning a template from one vcenter to another.
Let me check and get back to you for the above comment. I am not sure about the permission issue though.
@Akasurde .. the permission issue I am now seeing is the network associated with the source template does not exist on the target vcenter and it says I don't have permission to create a network there. I just want to clone a template from one vcenter to another. Does it clone the template from source vcenter to a VM on destination vcenter, then convert the destination VM to a template?
From the source vcenter:
Permission to perform this operation was denied. NoPermission.message.format The virtual machine or template has a NIC connected to a network that does not exist at destination host and user does not have the Host.Config.Network privilege at destination host. Host.Config.Network privilege is required to create a network.
Let me explain the bigger picture. We use packer to create and update VMware templates on a periodic basis. We want to do this on one ESX environment, then propagate the updated templates to the other ESX environments so we can use them for automated provisioning of new VMs. By definition, the source vCenter and destination vCenters will have different networks associated with them.
Is this the correct module to use to propagate ESX templates from one vCenter to another?
SUMMARY
I am using a ID with full admin rights on source and destination. The module fails on permissions checks.
ISSUE TYPE
COMPONENT NAME
ansible-collections/community.vmware/plugins/modules/vmware_guest_cross_vc_clone.py
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
macos big sur vsphere 7.0
STEPS TO REPRODUCE
EXPECTED RESULTS
I expect with full vmware admin rights on source and destination that the cloning will procede.
ACTUAL RESULTS
Permissions fail on trying to clone on the source.