community.vmware
community.vmware copied to clipboard
vmware_guest_disk: Don't work if a datastore is shared between several datacenters
SUMMARY
On our VMware environement, some datastores are presented on several datacenters which suppose an issue as when trying to add a new disk on a VMware server, we get this error: msg: Get datastore 'XX' in datacenter 'YY', not the configured datacenter 'ZZ'
ISSUE TYPE
- Bug Report
COMPONENT NAME
vmware_guest_disk
ANSIBLE VERSION
$ ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]. This feature will be removed from ansible-core
in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
ansible [core 2.11.12]
config file = /home/user/.ansible.cfg
configured module search path = ['/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
jinja version = 2.11.2
libyaml = True
COLLECTION VERSION
$ ansible-galaxy collection list community.general
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]. This feature will be removed from ansible-core
in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
[DEPRECATION WARNING]: [defaults]callback_whitelist option, normalizing names to new standard, use callbacks_enabled instead. This feature will be removed from ansible-core in version 2.15. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
# /usr/local/lib/python3.6/site-packages/ansible_collections
Collection Version
----------------- -------
community.general 2.5.2
CONFIGURATION
$ ansible-config dump --only-changed
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Nov 16 2020, 16:55:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]. This feature will be removed from ansible-core
in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
[DEPRECATION WARNING]: [defaults]callback_whitelist option, normalizing names to new standard, use callbacks_enabled instead. This feature will be removed from ansible-core in version 2.15. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
ANSIBLE_NOCOWS(/home/user/.ansible.cfg) = True
CALLBACKS_ENABLED(/home/user/.ansible.cfg) = ['profile_tasks', 'timer']
DEFAULT_BECOME(/home/user/.ansible.cfg) = True
DEFAULT_BECOME_METHOD(/home/user/.ansible.cfg) = sudo
DEFAULT_BECOME_USER(/home/user/.ansible.cfg) = root
DEFAULT_HOST_LIST(/home/user/.ansible.cfg) = ['/home/user/ansible/inventory']
DEFAULT_LOG_PATH(/home/user/.ansible.cfg) = /var/log/ansible.log
DEFAULT_MODULE_PATH(/home/user/.ansible.cfg) = ['/usr/share/ansible/plugins/modules']
DEFAULT_REMOTE_USER(/home/user/.ansible.cfg) = ansible
DEFAULT_ROLES_PATH(/home/user/.ansible.cfg) = ['/home/user/.ansible/roles', '/home/pbidault/user/roles', '/home/user/roles']
DEFAULT_STDOUT_CALLBACK(/home/user/.ansible.cfg) = yaml
DEFAULT_TIMEOUT(/home/user/.ansible.cfg) = 60
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /home/user/.vault_pass.txt
HOST_KEY_CHECKING(/home/user/.ansible.cfg) = False
INTERPRETER_PYTHON(/home/user/.ansible.cfg) = auto
RETRY_FILES_ENABLED(/home/user/.ansible.cfg) = False
OS / ENVIRONMENT
CentOS 7
STEPS TO REPRODUCE
Just try to add a new disk on a VMware VM on which the specified datastore is presented on several datacenters.
- name: Add {{ item.type| default('thin') }} disk type of {{ item.disk_size_gb }}GB
vmware_guest_disk:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ vcenter_datacenter }}"
name: "{{ vm_name }}"
disk:
- size_gb: "{{ item.disk_size_gb | replace('g','') }}"
type: "{{ item.type | default('thin') }}"
datastore: "{{ item.datastore if item.datastore is defined else datastore }}"
state: present
scsi_type: 'paravirtual'
scsi_controller: "{{ scsi_controller | default('1') }}"
unit_number: "{{ unit_number }}"
validate_certs: false
delegate_to: "{{ api_jump_host }}"
EXPECTED RESULTS
The disk should be added
ACTUAL RESULTS
The disk failed to be added if the first datacenter the datastore belongs to, found by Ansible, is not the one specified in the datacenter
parameter, with the following error output:
msg: Get datastore 'XX' in datacenter 'YY', not the configured datacenter 'ZZ'
Will there be a fix to this issue? Also, is it possible to remove the 'datacenter' parameter requirement, that way VC won't be an requirement.
have the same problem on vsphere 7.0.3 .. please advise if there is any work around for this. thanks
Same issue here with vSphere 7 and 8. Is it possible to add an option to specify Datacenter ?
For me, this simple patch does the trick:
--- vmware_guest_disk.py.orig 2024-05-02 10:11:24.585247331 +0200
+++ vmware_guest_disk.py 2024-05-02 10:10:57.286246669 +0200
@@ -956,11 +956,6 @@
# If user specified datastore cluster, keep track of that for determining datastore later
current_disk['datastore_cluster'] = datastore_cluster
elif datastore:
- ds_datacenter = get_parent_datacenter(datastore)
- if ds_datacenter.name != self.module.params['datacenter']:
- self.module.fail_json(msg="Get datastore '%s' in datacenter '%s', not the configured"
- " datacenter '%s'" % (datastore.name, ds_datacenter.name,
- self.module.params['datacenter']))
current_disk['datastore'] = datastore
current_disk['autoselect_datastore'] = False
elif disk['autoselect_datastore'] is not None:
After applying the patch, I'm able to add a disk to a VM no problem. I can't understand why this block of code is needed.