ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
349 stars 341 forks source link

vmware_guest: cannot choose between two datastores with parameter autoselect_datastore: True #266

Open razbag opened 4 years ago

razbag commented 4 years ago
SUMMARY

Trying to Deploy VM from template and I want to use autoselect_datastore: True paramter only for specific datastores for example I have three datastores ds-r1 ds-r5 and ds-r10

I want to use autoselect_datastore only for this two datastores ds-r5 and ds-r10 and I want that system automatically choose with less used datastore But I can't I try with list items it is not working

If someone can help please

Thanks in advance.

P.S I have limitation and cannot use datastore cluster function in Vcenter

ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/razmik/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Apr 15 2020, 17:20:14) [GCC 7.5.0]
OS / ENVIRONMENT

Ubuntu 18.04.4 LTS 4.15.0-106-generic

STEPS TO REPRODUCE

So what I expect that autoselect_datastore choose between ds-r5 and ds-r10 with filter less but it is not working and disk created in default template storage which is ds-r1

    disk:
      - size_gb: 25 # System
        datastore:
          - ds-r5
          - ds-r10
        autoselect_datastore: True

P.S play-book run without any error but VM disk create at the datastore where is located template

  tasks:

    - name: Create new VM from template {{ template }} to {{ vm_name }}
      vmware_guest:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: no
        datacenter: "{{ datacenter }}"
        state: present
        template: "{{ template }}"
        name: "{{ vm_name }}"
        cluster: HA cluster
        folder: /
        disk:
          - size_gb: 25 # System
            datastore:
              - ds-r5
              - ds-r10
            autoselect_datastore: True
        hardware:
          memory_mb: "{{ ram_size }}"
          num_cpus: "{{ cpu_count }}"
          num_cpu_cores_per_socket: 1
          hotadd_cpu: True
          hotremove_cpu: True
          hotadd_memory: Truea
        networks:
          - name: "{{ VLAN_ID }}"
            ip: "{{ ip_address }}"
            netmask: "{{ subnet_mask }}"
            gateway: "{{ gateway }}"
        wait_for_ip_address: True
        customization:
          domain: "{{ guest_domain }}"
      delegate_to: localhost
ACTUAL RESULTS
changed: [localhost] => {
    "changed": true, 
    "instance": {
        "annotation": "", 
        "current_snapshot": null, 
        "customvalues": {}, 
        "guest_consolidation_needed": false, 
        "guest_question": null, 
        "guest_tools_status": "guestToolsRunning", 
        "guest_tools_version": "11269", 
        "hw_cluster": "HA cluster", 
        "hw_cores_per_socket": 1, 
        "hw_datastores": [
            "ds-r1"
        ], 
        "hw_esxi_host": "esx1.********", 
        "hw_eth0": {
            "addresstype": "assigned", 
            "ipaddresses": null, 
            "label": "Network adapter 1", 
            "macaddress": "00:40:46:6d:3e:b1", 
            "macaddress_dash": "00-40-46-9d-3e-b1", 
            "portgroup_key": null, 
            "portgroup_portkey": null, 
            "summary": "vlanX"
        }, 
        "hw_files": [
            "[ds-r1] testvm.********/testvm.********.vmx", 
            "[ds-r1] testvm.********/testvm.********.nvram", 
            "[ds-r1] testvm.********/testvm.********.vmsd", 
            "[ds-r1] testvm.********/testvm.********.vmdk"
        ], 
        "hw_folder": "/vm", 
        "hw_guest_full_name": "", 
        "hw_guest_ha_state": true, 
        "hw_guest_id": null, 
        "hw_interfaces": [
            "eth0"
        ], 
        "hw_is_template": false, 
        "hw_memtotal_mb": 2048, 
        "hw_name": "testvm.********", 
        "hw_power_status": "poweredOn", 
        "hw_processor_count": 2, 
        "hw_product_uuid": "421df603-55af-524b-69d3-1779616eaeaf", 
        "hw_version": "vmx-14", 
        "instance_uuid": "501d845b-9290-0bba-01ca-a493967e1cc4", 
        "ipv4": "XX.XX.XX.XX", 
        "ipv6": null, 
        "module_hw": true, 
        "moid": "vm-4052", 
        "snapshots": [], 
        "vimref": "vim.VirtualMachine:vm-4052", 
        "vnc": {}
    }, 
    "invocation": {
        "module_args": {
            "annotation": null, 
            "cdrom": [], 
            "cluster": "HA cluster", 
            "convert": null, 
            "customization": {
                "dns_servers": [
                    "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
                    "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
                ], 
                "dns_suffix": [
                    "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
                ], 
                "domain": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
            }, 
            "customization_spec": null, 
            "customvalues": [], 
            "datacenter": "NEW_DC", 
            "datastore": null, 
            "disk": [
                {
                    "autoselect_datastore": true, 
                    "datastore": [
                        "db-r1", 
                        "db-r10"
                    ], 
                    "size_gb": 25
                }
            ], 
            "esxi_hostname": null, 
            "folder": "/", 
            "force": false, 
            "guest_id": null, 
            "hardware": {
                "hotadd_cpu": true, 
                "hotadd_memory": true, 
                "hotremove_cpu": true, 
                "memory_mb": "2048", 
                "num_cpu_cores_per_socket": 1, 
                "num_cpus": "2"
            }, 
            "hostname": "hostname", 
            "is_template": false, 
            "linked_clone": false, 
            "name": "testvm.********", 
            "name_match": "first", 
            "networks": [
                {
                    "gateway": "", 
                    "ip": "XX.XX.XX.XX", 
                    "name": "vlanX", 
                    "netmask": "XX.XX.XX.XX", 
                    "type": "static"
                }
            ], 
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "port": 443, 
            "proxy_host": null, 
            "proxy_port": null, 
            "resource_pool": null, 
            "snapshot_src": null, 
            "state": "present", 
            "state_change_timeout": 0, 
            "template": "Ubuntu_18_04_LTS", 
            "use_instance_uuid": false, 
            "username": "ansible", 
            "uuid": null, 
            "validate_certs": false, 
            "vapp_properties": [], 
            "wait_for_customization": false, 
            "wait_for_ip_address": true
        }
    }
}
META: ran handlers
META: ran handlers

PLAY RECAP ********************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
Tomorrow9 commented 4 years ago

Hi @razbag the logic is if you specify the parameter "autoselect_datastore" and set it to true, it will get all the VMFS datastores of ESXi host specified or the "cluster" specified, then check if these datastores' name contains the "datastore" parameter value. Here you set the "datastore" to "['ds-r5', 'ds-r10']", I think there is no matched datastore name. So it will use the template disk file datastore if this datastore is also in the same "datacenter", or it will select a datastore in this vCenter with largest free space. Thanks.

cluster: HA cluster
folder: /
disk:
    - size_gb: 25 # System
       datastore:
           - ds-r5
           - ds-r10
       autoselect_datastore: True
razbag commented 4 years ago

Hi @razbag the logic is if you specify the parameter "autoselect_datastore" and set it to true, it will get all the VMFS datastores of ESXi host specified or the "cluster" specified, then check if these datastores' name contains the "datastore" parameter value. Here you set the "datastore" to "['ds-r5', 'ds-r10']", I think there is no matched datastore name. So it will use the template disk file datastore if this datastore is also in the same "datacenter", or it will select a datastore in this vCenter with largest free space. Thanks.

cluster: HA cluster
folder: /
disk:
    - size_gb: 25 # System
       datastore:
           - ds-r5
           - ds-r10
       autoselect_datastore: True

Hi @Tomorrow9 ,

I am agree with logic but it doesn't work also but when I set only one datastore it is working fine for example cluster: HA cluster folder: / disk:

or

cluster: HA cluster folder: / disk:

it is working fine.

Thanks, Razmik

Tomorrow9 commented 4 years ago

Hi @razbag is the result of your examples above is: it selects datastore "ds-r5" and "ds-r10" to deploy VM separately?

If you want it to select one datastore in the configured two datastores, then that must be a feature request for "vmware_guest" to support selecting one datastore in specified datastore list instead of all datastores available.

razbag commented 4 years ago

Hi @razbag is the result of your examples above is: it selects datastore "ds-r5" and "ds-r10" to deploy VM separately?

If you want it to select one datastore in the configured two datastores, then that must be a feature request for "vmware_guest" to support selecting one datastore in specified datastore list instead of all datastores available.

Hi @Tomorrow9 , This is just an example with individuals datastore it works fine example is this one

cluster: HA cluster folder: / disk:

but what I want is use both datastores in one command with autoselect_datastore: example is

cluster: HA cluster
folder: /
disk:
- size_gb: 25 # System
  datastore:
           - ds-r5
           - ds-r10
  autoselect_datastore: True

and autoselect_datastore with value true can find and select less used between this listed datastore:(in my case ds-r5 and ds-r10)

I just want to know if this is possible or I have some misconfiguration in my playbook ?

Thanks in advance

Tomorrow9 commented 4 years ago

@razbag now selecting from a specified datastore list is not supported as I know. But I think this is a use case that user don't want to deploy VM to all available datastores just some of them.

A way to let it work is set the datastores' names to "ds-r1", "ds-r5-test", "ds-r10-test", and write as below, I think it can work to find datastores with keyword "test" in the name.

cluster: HA cluster
folder: /
disk:
  - size_gb: 25 # System
     datastore: 'test'
     autoselect_datastore: True
razbag commented 4 years ago

@razbag now selecting from a specified datastore list is not supported as I know. But I think this is a use case that user don't want to deploy VM to all available datastores just some of them.

A way to let it work is set the datastores' names to "ds-r1", "ds-r5-test", "ds-r10-test", and write as below, I think it can work to find datastores with keyword "test" in the name.

cluster: HA cluster
folder: /
disk:
  - size_gb: 25 # System
     datastore: 'test'
     autoselect_datastore: True

Hi @Tomorrow9

It is really working with change naming of datastores and I run test and confirm that this is working. Thanks for this workaround. but let me ask you my latest question :) are you planning to implement selecting from a specified datastore list I think it is very useful

Thanks in advance, Razmik

Akasurde commented 3 years ago

@razbag We are not planning to add this feature to the near future. Please feel free to open pull request.

needs_info