Why is "datacenter" a required parameter for vmware modules?

29 views
Skip to first unread message

MKPhil

unread,
Aug 27, 2019, 8:38:54 AM8/27/19
to Ansible Development
In many vmware_* modules, the datacenter parameter is marked as required - but is it really needed?

I ask because I've written a module, based on vmware_guest_find, that returns the Datacenter for a given VM and VCenter, which I can then feed in to the other "official" modules. My module uses the built-in function "get_parent_datacenter" (defined in https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/vmware.py) so I'm not inventing anything particularly new. My point is that if I, an amateur Python coder at best, can do this, why can't the official modules do it by default?  Is there some reason for the current behaviour that I am missing?

I'm not really confident (yet) in editing the official modules and submitting Pull Requests etc. but am happy to share my code with someone who can do this.


Christoph Wegener

unread,
Aug 27, 2019, 9:32:04 AM8/27/19
to MKPhil, Ansible Development
On Tue, 27 Aug 2019 at 22:38, MKPhil wrote:
> In many vmware_* modules, the datacenter parameter is marked as
> required - but is it really needed?

Can you point to any particular module that has 'datacenter' marked as
a required parameter?


MKPhil

unread,
Aug 27, 2019, 9:42:58 AM8/27/19
to Ansible Development

Kai Stian Olstad

unread,
Aug 27, 2019, 1:10:45 PM8/27/19
to ansibl...@googlegroups.com
On 27.08.2019 14:38, MKPhil wrote:
> I ask because I've written a module, based on vmware_guest_find, that
> returns the Datacenter for a given VM and VCenter, which I can then feed in
> to the other "official" modules. My module uses the built-in function
> "get_parent_datacenter" (defined in
> https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/vmware.py)
> so I'm not inventing anything particularly new. My point is that if I, an
> amateur Python coder at best, can do this, why can't the official modules
> do it by default? Is there some reason for the current behaviour that I am
> missing?

If I have two VM both called hostA, one in datacenter-north and one in datacenter-south, which one do you choose?


--
Kai Stian Olstad

MKPhil

unread,
Aug 28, 2019, 10:48:58 AM8/28/19
to Ansible Development
That's not a datacenter issue - you can have two VMs with the same name in the same datacenter but VMWare does not recommend this - https://kb.vmware.com/s/article/2108769

vmware_guest_facts has a "name_match" parameter "If multiple virtual machines matching the name, use the first or last found." (see https://docs.ansible.com/ansible/latest/modules/vmware_guest_facts_module.html#vmware-guest-facts-module) to cater for this but in my opinion (I support over 20,000 vms), you should probably really aim to have unique names.

Kai Stian Olstad

unread,
Aug 29, 2019, 12:22:15 PM8/29/19
to ansibl...@googlegroups.com
On 28.08.2019 16:48, MKPhil wrote:
> That's not a datacenter issue - you can have two VMs with the same name in
> the same datacenter but VMWare does not recommend this -
> https://kb.vmware.com/s/article/2108769

I would say it is.
A datacenter is a namespace that makes it possible to have the same name for VMs, templates, hosts, clusters, networks and datastores across datacenters. But must of them need to be uniq within the datacenter.


> vmware_guest_facts has a "name_match" parameter "If multiple virtual
> machines matching the name, use the first or last found." (see
> https://docs.ansible.com/ansible/latest/modules/vmware_guest_facts_module.html#vmware-guest-facts-module)
> to cater for this but in my opinion (I support over 20,000 vms), you should
> probably really aim to have unique names.

IMHO it's missing the option fail.


--
Kai Stian Olstad

Gonéri Le Bouder

unread,
Aug 29, 2019, 1:01:04 PM8/29/19
to Ansible Development
Hi,

If no datacenter is set, the default is 'ha-datacenter', not 'all the DC'
as the users may expect. So unless you are aware of that, the playbook will
access the wrong datacenter. This was source of confusion for the users.

By enforcing the parameter, we ensure the user select the correct DC.
This is now listed in the VMware guidlines:

-- 
    Gonéri
Reply all
Reply to author
Forward
0 new messages