Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with vmware_guest module (folder is not required but giving error) #28463

Closed
abhinav-chittora opened this issue Aug 21, 2017 · 35 comments · Fixed by #33479
Closed

Issue with vmware_guest module (folder is not required but giving error) #28463

abhinav-chittora opened this issue Aug 21, 2017 · 35 comments · Fixed by #33479
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. cloud module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. vmware VMware community

Comments

@abhinav-chittora
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

vmware_guest

ANSIBLE VERSION
ansible 2.4.0 (devel 4653f892c8) last updated 2017/08/21 13:26:39 (GMT +550)
  config file = /srv/IT-DevOps/ansible/vmware-vmmgmt/ansible.cfg
  configured module search path = [u'/srv/IT-DevOps/ansible/library']
  ansible python module location = /srv/ansible/lib/ansible
  executable location = /srv/ansible/bin/ansible
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
CONFIGURATION
host_key_checking = False
roles_path = ../roles
library = ../library
OS / ENVIRONMENT
NAME="CentOS Linux"
VERSION="7 (Core)"
SUMMARY

When running the vmwre_guest module and we don't specify the folder name (which is not a required parameter), and we have a top level folder before any data center, it fails with error:
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "No folder matched the path: /vm"}

STEPS TO REPRODUCE

At vmware level, create a folder before creating a datacenter and rest hierarchy will be same as usual. You can create cluster & resource pool as you want. When you try to create a virtual machine using vmware_guest module, it takes default value of folder as /vm, which is not true in this case as correct path is /[first folder]/[data center]/vm. Hence the creation of virtual machine fails. This is the same case with other vmware modules such as vmware_snapshot.

- name: Deploy VM from template or Remove VM based on Choice
   vmware_guest:
    hostname: "{{ vmware_vcenter }}"
    username: "{{ vmware_user }}"
    password: "{{ vmware_pass }}"
    name: "{{ vmware_guest }}"
    datacenter: "{{ vmware_datacenter }}"
    template: "{{ vmware_template }}"
    cluster: "{{ vmware_cluster }}"
    resource_pool: "{{ vmware_resource_pool }}"
    #folder: "{{ vmware_folder }}"
    networks: "{{ vmware_networks }}"
    hardware:
      memory_mb: "{{ vmware_memory }}"
      num_cpus: "{{ vmware_cpu }}"
    validate_certs: no
    state: "{{ state }}"
    force: yes
    wait_for_ip_address: yes
EXPECTED RESULTS

It should create the virtual machine without giving any error with template specified.

ACTUAL RESULTS

It failed and no virtual machine is created.

@abhinav-chittora abhinav-chittora changed the title Issue with vmware_guest module Issue with vmware_guest module (folder is not required but giving error) Aug 21, 2017
@ansibot
Copy link
Contributor

ansibot commented Aug 21, 2017

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report cloud module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. vmware VMware community labels Aug 21, 2017
@Akasurde
Copy link
Member

@abhinav-chittora vmware_guest provides idempotency, that means code will try to find virtual machine before it tries to create a new one. Here, in your case it is not able to find virtual machine so failing with following message

No folder matched the path: /vm

which is due to the fact that vmware_guest sets value of folder to /vm if not provided by user.

@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Aug 21, 2017
@nre-ableton
Copy link
Contributor

@Akasurde What should the user do if no folder is needed? Specifying an empty string or / will both throw the error No folder matched the path: . Using the same value as the datacenter throws the error No folder matched the path: /MyDatacenterName.

We don't use folders in my company, but I even had our administrators create me one just so I could work around this behavior. Sadly, it didn't work, because while some operations succeed with the folder, others fail mysteriously and require the full datacenter + folder path.

Regardless, the recent changes in vmware_guest.py on develop mean that the folder argument is only optional if your vSphere installation does not have a folder called /vm. Otherwise you will definitely get an error if it is not specified when the module looks for stuff inside a folder that doesn't exist.

I would be happy to do some git bisecting and help to find the specific cause of this error, if necessary.

@Akasurde
Copy link
Member

Akasurde commented Aug 22, 2017

I agree that folder is an optional parameter but then there is no "magic" method to find a virtual machine which can find the unique vm. Also, create and clone operation requires folder value internally.

@abhinav-chittora Could you please paste output of govc find /? also, can you try vmware_guest_find module to find out folder of virtual machine. You can use the value of folder from vmware_guest_find output to use in vmware_guest module. something like follow -

---
- name: Sample Guest find
  hosts: localhost
  tasks:
    - name: Guest find
      vmware_guest_find:
        hostname: 0.0.0.0
        username: user
        password: pass
        validate_certs: no
        name: DC0_H0_VM0
        datacenter: DC0
      register: folder_name

    - name: Create vm if not found
      vmware_guest:
        datacenter: DC0
        esxi_hostname: DC0_H0
        hostname: 127.0.0.1
        name: SampleVM06
        validate_certs: False
        username: user
        password: pass
        folder: "{{ folder_name['folders'] }}"
        state: present
        guest_id: ubuntu_id
        resource_pool: myrp
        disk:
         - size_gb: 1
            type: thin
            datastore: LocalDS_0
        hardware:
            memory_mb: 512
            num_cpus: 1
            osid: centos64guest
            scsi: paravirtual

@nre-ableton Let me know your views so that we can resolve this.

@nre-ableton
Copy link
Contributor

@Akasurde My view is pretty simple: the folder parameter should be optional, in the sense that if it is not specified, then the module still works. That is currently not the case. 😉

@nre-ableton
Copy link
Contributor

@Akasurde So I spent a bit of time looking at vmware_guest.py and came up with a branch, which you can diff against devel here: https://github.com/ansible/ansible/compare/devel...nre-ableton:nre_devel_folder-default-none?expand=1 . With that patch, my Ansible playbooks work again for cloning, not only when a folder is given, but also when the folder option is not present.

Since I am not terribly familiar with this code, I don't dare to submit this as a PR just yet, as I suspect that there is the risk that path building is broken when using the datacenter in the path (see the comment for commit https://github.com/nre-ableton/ansible/commit/7770b880b2bc8a0a10bdcf324e1cda5a41d3bad9 for more explanation). When I tried using dcpath, it always resulted in the 'No folder matched the path' error being thrown.

Nevertheless, I think that the key idea in this patch is that the default value of params['folder'] should be None instead of /vm. @Akasurde what do you think about the general idea of this patch? Does it make sense? Or would it be just solving the problem for me, but breaking it for everybody else? 🙂 Please let me know what you think about this idea.

@cigamit
Copy link
Contributor

cigamit commented Aug 24, 2017

Ya, your patch will break a lot of scenarios. You completely removed the use of dcpath, which is key for scenarios where Data Centers are nested under folders themselves. I think a few of the other scenarios are broken also.

Regardless, the recent changes in vmware_guest.py on develop mean that the folder argument is only optional if your vSphere installation does not have a folder called /vm. Otherwise you will definitely get an error if it is not specified when the module looks for stuff inside a folder that doesn't exist.

What I think you are missing is that /vm is not an actual "user" folder that you can see, it is the internal VMWare folder where all VMs are located. Every VCenter will have this internal folder. That is why we default to it, and if you don't prepend it to your folder path, we add it.

folder: /
and omitting the folder should technically work. I will go back through the current code and replay all the various scenarios to ensure they each will work (including omitting the folder).

@nre-ableton
Copy link
Contributor

@cigamit Yeah, I suspected as such. However, when I tried to use dcpath, I got the 'No folder matched the path' error every single time, and also regardless of how I tried to pass in a folder argument (also just to be clear, with no folder, it also didn't work).

Yeah, I gathered that /vm is an internal path which must be added, and I understand the logic of checking for that. Still, I don't think it makes sense to default to it, especially because it is an internal VMWare thing. Checking for None and then defaulting to /vm is something that should happen under the surface.

Anyways, I think the issue at hand is trying to figure out why dcpath doesn't work for our installation. Please let me know if I should provide any troubleshooting information or if I can help out in any way.

@abhinav-chittora
Copy link
Author

abhinav-chittora commented Sep 5, 2017

Hi @Akasurde, @nre-ableton , @cigamit

Sorry for late reply here. I was down due to health issues. I found the folder path where the virtual machine need to be located using govc find / and when I supply the folder path, it still gives the same error msg i.e. "msg": "No folder matched the path: /Datacenter/AM-Datacenter/vm/DCOS"

Here is the govc find / output which I trunked a to fit and include all required pieces. The folder where we need to create VM is /Datacenter/AM-Datacenter/vm/DCOS

REMOVED AS PER REPORTER'S REQUEST

Meanwhile, I will check possibility of using vmware_guest_find and use folder from there in vmware_guest, but my point is running vmware_guest_find on complete vcenter inventory( which is very big in my case and take 10-15 minute to find a VM) is unnecessary.

@abhinav-chittora
Copy link
Author

@Akasurde : In case the virtual machine not found in /vm folder, it should create the virtual machine instead of giving error that the folder /vm is not found.

@dagwieers
Copy link
Contributor

dagwieers commented Sep 5, 2017

@abhinav-chittora If you have a playbook using non-existing folders, you should be creating that folder in a previous task. We deliberately chose not to have vmware_guest create folders for 2 reasons:

  • vmware_guest manages VMs, not folders (so you need to use a module that manages folders)
  • Creating a VM in a folder that does not exist, might as well be a user-error, rather than the desired state

More information from #20291

@abhinav-chittora
Copy link
Author

Hi @dagwieers
In my case the folder exists but the virtual machine which I need create is not available in vcenter inventory, but each time I run the playbook, I get the error that the folder is not available.

Error msg: No folder matched the path: /Datacenter/AM-Datacenter/vm/DCOS"

@abhinav-chittora
Copy link
Author

@Akasurde : I tried to use vmware_guest_find module to get vmware_folder but if the virtual machine is not available, it fails with error "msg": "Unable to find folders for VM virtual-machine1". In that case, I am not able to create virtual-machine1 in specified folder i.e. /Datacenter/AM-Datacenter/vm/DCOS which is available in vcenter inventory.

@abhinav-chittora
Copy link
Author

@jctanner @nerzhul, could you please suggest something here?

@jctanner
Copy link
Contributor

@abhinav-chittora Please use my walk script to validate the paths ...

https://github.com/jctanner/ansible-tools/blob/master/vmware/vmware_walk.py

[jctanner@jctanner-jumphost ~]$ ansible-tools/vmware/vmware_walk.py --hostname=XXXX --username=XXXX --password=XXXX --filter='Jimmy Test'  --fuzzytest

... lots of output ...

# valid inputs for findByInventoryPath
['/MNS/vm/RHLabs/Jimmy Test', 'MNS/vm/RHLabs/Jimmy Test']

In your case, the filter would be "DCOS".

needs_info

@ansibot ansibot added the needs_info This issue requires further information. Please answer any outstanding questions. label Sep 14, 2017
@abhinav-chittora
Copy link
Author

I will use this script to find the path and use the path to create new virtual machine. I will update the result here.

@ansibot ansibot removed the needs_info This issue requires further information. Please answer any outstanding questions. label Sep 20, 2017
@abhinav-chittora
Copy link
Author

@jctanner I run the script that you provided and It returned the same path that I was using. So I am back to square one. The problem still exists.

@ansibot
Copy link
Contributor

ansibot commented Oct 14, 2017

@frado22
Copy link

frado22 commented Nov 26, 2017

Hi,

I've got the same problem, except that I have a folder in which I have already VM (ZABBIX3). So I began with ansible module vmware_guest_find in order to find the full folder path, and I give it to the vmware_guest module. Here is the result log:

TASK [vmware_clone_template : Find Guest's Folder using name] *******************************************************************************************

ok: [lxezfee1.eram.loc -> localhost]

TASK [vmware_clone_template : debug] ********************************************************************************************************************

ok: [lxezfee1.eram.loc] => {}

MSG:

{u'folders': [u'/ERAM/vm/ZABBIX3'], 'failed': False, 'changed': False}


TASK [vmware_clone_template : Create a VM from a template] **********************************************************************************************

fatal: [lxezfee1.eram.loc -> localhost]: FAILED! => {
    "changed": false,
    "failed": true
}

MSG:

No folder matched the path: /ERAM/vm/ZABBIX3

        to retry, use: --limit @/ansible/playbooks/role.retry

PLAY RECAP **********************************************************************************************************************************************

lxezfee1.eram.loc          : ok=2    changed=0    unreachable=0    failed=1

As you see I got an error on the folder name for creation a VM from a template, but this folder was correctly discovered at the previous step.

My ansible version is ansible-2.4.1.0-1.el7.noarch on RHEL 7.4

@Akasurde
Copy link
Member

@frado22 Could you please paste your playbook ?

@frado22
Copy link

frado22 commented Nov 27, 2017

Here is my role (role name: vmware_clone_template):

- name: Find Guest's Folder using name
  vmware_guest_find:
    hostname: vcenter.eram.loc
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    datacenter: "{{ vmware.datacenter }}"
    validate_certs: no
    name: lxezfed1
  delegate_to: localhost
  register: vm_folder

- debug:
    msg: "{{ vm_folder }}"

- name: Create a VM from a template
  vmware_guest:
    hostname: vcenter.eram.loc
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    validate_certs: no
    annotation: "{{ vmware.annotation }}"
    folder: "{{ vmware.folder }}"
    force: yes
    datacenter: "{{ vmware.datacenter }}"
    name: "{{ vmware.vm_name }}"
    state: poweredoff
    template: "{{ vmware.template }}"
    disk: "{{ vmware.disk }}"
    hardware:
      memory_mb: "{{ vmware.memory_mb }}"
      num_cpus: "{{ vmware.num_cpus }}"
    networks: "{{ vmware.networks }}"
  delegate_to: localhost
  register: deploy

My vars for host lxezfee1.eram.loc:

vmware:
  template: t-rhel7.2-stable
  datacenter: SPMT
  cluster: C3-ADM
  memory_mb: 4096
  num_cpus: 2
  disk:
  - size_gb: 25
    type: thick
    datastore: esxs5_SAS_prod8
  - size_gb: 15
    type: thick
    datastore: esxs5_SAS_prod8
  vm_name: "{{ inventory_hostname.split('.')[0] }}"
  annotation: "Serveur frontend Zabbix 3 production"
  folder: /ERAM/vm/ZABBIX3
  networks:
  - name: DVPG-MGMT-SUPERVISIONS
    type: vmxnet3

My playbook (role.yml):

- hosts: "{{ role_hosts | default('none') }}"
  gather_facts: "{{ gather |default('True') }}"
  max_fail_percentage: "{{ stop_play_percentage | default('100') }}"
  roles:
  - role: "{{ role_name }}"

And the command I launch:

ansible-playbook -i <my_inventory_folder> role.yml -e role_name=vmware_clone_template -e role_hosts=lxezfee1* -e vcenter_username=xxxxxxx -e vcenter_password=yyyyyyyy -e gather=False

Other (useful?) information, with govc I got this:

#govc ls -u vcenter.eram.loc /ERAM/SPMT/vm/ZABBIX3
/ERAM/SPMT/vm/ZABBIX3/lxezpxd1
/ERAM/SPMT/vm/ZABBIX3/lxezpxd2
/ERAM/SPMT/vm/ZABBIX3/lxezbdd2
/ERAM/SPMT/vm/ZABBIX3/lxezbdd1
/ERAM/SPMT/vm/ZABBIX3/lxezfed1
/ERAM/SPMT/vm/ZABBIX3/lxezsvd1
#govc ls -u vcenter.eram.loc /ERAM/vm/ZABBIX3

So I test for vmware.folder=/ERAM/SPMT/vm/ZABBIX3 and vmware.folder=/ERAM/vm/ZABBIX3 and the result is the same.

TASK [vmware_clone_template : Create a VM from a template] ***********************************************************************************************************************************************************************************

fatal: [lxezfee1.eram.loc -> localhost]: FAILED! => {
    "changed": false,
    "failed": true
}

MSG:

No folder matched the path: /ERAM/SPMT/vm/ZABBIX3

@Akasurde
Copy link
Member

@frado22 I created similar setup in my environment

govc find /
/
/F0
/F0/DC0
/F0/DC0/vm
/F0/DC0/vm/F0
/F0/DC0/vm/F0/DC0_H0_VM0
...
/F0/DC0/vm/F0/DC0_H0_VM004
...

In order to create DC0_H0_VM004 , I am using following PB

---
- name: Sample to create VM
  hosts: localhost
  gather_facts: false
  tasks:
    - name: sample task
      vmware_guest:
        datacenter: DC0
        esxi_hostname: DC0_H0
        hostname: 127.0.0.1
        resource_pool: DC0_C1_RP1
        name: DC0_H0_VM004
        folder: /F0
        validate_certs: False
        guest_id: sample
        username: user
        password: pass
        state: poweredon
        disk:
          - size_gb: 1
            type: thin
            datastore: LocalDS_0
        hardware:
            memory_mb: 4096
            num_cpus: 4
            osid: centos64guest
            scsi: paravirtual

You will notice that I am using /F0 which is in vmFolder as Folder value.

Could you please try - /ZABBIX3 as Folder value and this #33337 for debugging?

@frado22
Copy link

frado22 commented Nov 29, 2017

@Akasurde

I test your fix in my environment.

I duplicate the task in order that you see the result in one output:

  • For the first task I set folder: ZABBIX3
  • For the second task I unset folder
  • For the third task I set folder: /ZABBIX3
  • For the fourth task I set folder: /ERAM/SPMT/vm/ZABBIX3

Here is the result:

TASK [vmware_clone_template : Create a VM from a template folder: ZABBIX3] **************************************


fatal: [lxezfee1.eram.loc -> localhost]: FAILED! => {
    "changed": false,
    "details": {
        "datacenter": "SPMT",
        "datacenter_path": "/ERAM",
        "folder": "/ZABBIX3",
        "full_search_path": "/ERAMSPMT/vm/ZABBIX3"
    }
}

MSG:

No folder /ZABBIX3 matched in the search path : /ERAMSPMT/vm/ZABBIX3

...ignoring

TASK [vmware_clone_template : Create a VM from a template no folder set] **************************************


fatal: [lxezfee1.eram.loc -> localhost]: FAILED! => {
    "changed": false,
    "details": {
        "datacenter": "SPMT",
        "datacenter_path": "/ERAM",
        "folder": "/vm",
        "full_search_path": "/ERAMSPMT/vm"
    }
}

MSG:

No folder /vm matched in the search path : /ERAMSPMT/vm

...ignoring

TASK [vmware_clone_template : Create a VM from a template folder /ZABBIX3] **************************************


fatal: [lxezfee1.eram.loc -> localhost]: FAILED! => {
    "changed": false,
    "details": {
        "datacenter": "SPMT",
        "datacenter_path": "/ERAM",
        "folder": "/ZABBIX3",
        "full_search_path": "/ERAMSPMT/vm/ZABBIX3"
    }
}

MSG:

No folder /ZABBIX3 matched in the search path : /ERAMSPMT/vm/ZABBIX3

...ignoring

TASK [vmware_clone_template : Create a VM from a template folder: /ERAM/SPMT/vm/ZABBIX3] **************************************


changed: [lxezfee1.eram.loc -> localhost]

So your resolution is working for the full path, but not for the relative one, nor if I do not set any folder.
Another minor bug:

  • As you see there is a MSG issue on the folder name in case of error, a missing "/" between the root folder and the datacenter name

Notes:

  • I can't just update the file vmware_guest.py. I had to use the latest ansible-devel version to test your fix. Any hope that your fix be applied in a 2.4.x version? Or I have to update all vmware* module files in 2.4?
  • With this version I also encountered bug vmware_guest module: "Failed to find a matching datastore #30327 that I resolve by adding esxi_hostname in my task

@Akasurde
Copy link
Member

@frado22 Just I expected. I will fix "missing /" issue. Also, I will try to backport this change in 2.4.x branch.

@Akasurde
Copy link
Member

@abhinav-chittora Could you please try adding folder as /DCOS considering AM-Datacenter is your datacenter" while creating VM inside - /Datacenter/AM-Datacenter/vm/DCOS ?

@abhinav-chittora
Copy link
Author

abhinav-chittora commented Nov 29, 2017 via email

@abhinav-chittora
Copy link
Author

@Akasurde, I tried with /DCOS as folder but getting error that no folder matched the path: /DCOS

Here is the playbook execution results: -


TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [localhost]

TASK [vmware-vmmgmt : Set vmware network mac and vlan settings] **********************************************************************************************
skipping: [localhost]

TASK [vmware-vmmgmt : Deploy VM from template or Remove VM based on Choice] **********************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "No folder matched the path: /DCOS"}
        to retry, use: --limit @/srv/IT-DevOps/ansible/vmware-vmmgmt/vmware-vmmgmt.retry

PLAY RECAP ***************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1

Playbook looks like this: -

---
- include: vmware_netconfig.yml
  when: vmware_netconfig

- name: Deploy VM from template or Remove VM based on Choice
  vmware_guest:
    hostname: "{{ vmware_vcenter }}"
    username: "{{ vmware_user }}"
    password: "{{ vmware_pass }}"
    name: "{{ vmware_guest }}"
    datacenter: "{{ vmware_datacenter }}"
    template: "{{ vmware_template }}"
    cluster: "{{ vmware_cluster }}"
    resource_pool: "{{ vmware_resource_pool }}"
    folder: "{{ vmware_folder }}"
    networks: "{{ vmware_networks }}"
    hardware:
      memory_mb: "{{ vmware_memory }}"
      num_cpus: "{{ vmware_cpu }}"
    validate_certs: no
    state: "{{ state }}"
    force: yes
    wait_for_ip_address: yes

Environment: -

ansible 2.4.2.0 (detached HEAD 880cb223b7) last updated 2017/11/29 23:40:56 (GMT +550)
  config file = /srv/IT-DevOps/ansible/vmware-vmmgmt/ansible.cfg
  configured module search path = [u'/srv/IT-DevOps/ansible/library']
  ansible python module location = /srv/ansible/lib/ansible
  executable location = /srv/ansible/bin/ansible
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

I tested with other ansible version and getting following error: -
Ansible version

ansible 2.3.2.0
  config file = /srv/IT-DevOps/ansible/vmware-vmmgmt/ansible.cfg
  configured module search path = [u'../library']
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [vmware-vmmgmt : Set vmware network mac and vlan settings] ****************
skipping: [localhost]

TASK [vmware-vmmgmt : Deploy VM from template or Remove VM based on Choice] ****
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "No folder matched the path: /vm/DCOS"}
        to retry, use: --limit @/srv/IT-DevOps/ansible/vmware-vmmgmt/vmware-vmmgmt.retry

PLAY RECAP *********************************************************************

Even with latest ansible code, the error is same: -

ansible 2.5.0 (devel 3d63ecb6f3) last updated 2017/11/24 13:16:25 (GMT +550)
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /srv/ansible/lib/ansible
  executable location = /srv/ansible/bin/ansible
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
PLAY [localhost] *********************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [localhost]

TASK [vmware-vmmgmt : Set vmware network mac and vlan settings] **********************************************************************************************
skipping: [localhost]

TASK [vmware-vmmgmt : Deploy VM from template or Remove VM based on Choice] **********************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "No folder matched the path: /DCOS"}
        to retry, use: --limit @/srv/IT-DevOps/ansible/vmware-vmmgmt/vmware-vmmgmt.retry

PLAY RECAP ***************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1

And with complete path as /Datacenter/AM-Datacenter/vm/DCOS & ansible version 2.5.0 (devel 3d63ecb) , the VM is deployed but the module returned error: -

PLAY [localhost] *********************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [localhost]

TASK [vmware-vmmgmt : Set vmware network mac and vlan settings] **********************************************************************************************
skipping: [localhost]

TASK [vmware-vmmgmt : Deploy VM from template or Remove VM based on Choice] **********************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: }
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_C2T2lK/ansible_module_vmware_guest.py\", line 1620, in <module>\n    main()\n  File \"/tmp/ansible_C2T2lK/ansible_module_vmware_guest.py\", line 1616, in main\n    module.exit_json(**result)\n  File \"/tmp/ansible_C2T2lK/ansible_modlib.zip/ansible/module_utils/basic.py\", line 2258, in exit_json\n  File \"/tmp/ansible_C2T2lK/ansible_modlib.zip/ansible/module_utils/basic.py\", line 2251, in _return_formatted\n  File \"/tmp/ansible_C2T2lK/ansible_modlib.zip/ansible/module_utils/basic.py\", line 488, in remove_values\n  File \"/tmp/ansible_C2T2lK/ansible_modlib.zip/ansible/module_utils/basic.py\", line 471, in _remove_values_conditions\nTypeError: Value of unknown type: <class 'pyVmomi.VmomiSupport.vim.vm.RuntimeInfo.DasProtectionState'>, (vim.vm.RuntimeInfo.DasProtectionState) {\n   dynamicType = <unset>,\n   dynamicProperty = (vmodl.DynamicProperty) [],\n   dasProtected = true\n}\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
        to retry, use: --limit @/srv/IT-DevOps/ansible/vmware-vmmgmt/vmware-vmmgmt.retry

PLAY RECAP ***************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1

@frado22
Copy link

frado22 commented Nov 29, 2017

Hi,

@Akasurde, thanks for your time.

So I loop over this folder list:

  with_items:
  - ""
  - /
  - /vm
  - /ZABBIX3
  - ZABBIX3
  - ERAM/SPMT/vm/ZABBIX3
  - /ERAM/SPMT/vm/ZABBIX3

Here is the result:

PLAY [lxezfee1.eram.loc] **************************************************************************************************************************************************************************


TASK [vmware_clone_template : Create a VM from a template **************************************************************************************************************************************************************************
failed: [lxezfee1.eram.loc -> localhost] (item=) => {
    "changed": false,
    "details": {
        "datacenter": "SPMT",
        "datacenter_path": "/ERAM",
        "folder": "",
        "full_search_path": "/ERAMSPMT/vm/"
    },
    "item": ""
}

MSG:

No folder  matched in the search path : /ERAMSPMT/vm/

failed: [lxezfee1.eram.loc -> localhost] (item=/) => {
    "changed": false,
    "details": {
        "datacenter": "SPMT",
        "datacenter_path": "/ERAM",
        "folder": "",
        "full_search_path": "/ERAMSPMT/vm/"
    },
    "item": "/"
}

MSG:

No folder  matched in the search path : /ERAMSPMT/vm/

failed: [lxezfee1.eram.loc -> localhost] (item=/vm) => {
    "changed": false,
    "details": {
        "datacenter": "SPMT",
        "datacenter_path": "/ERAM",
        "folder": "/vm",
        "full_search_path": "/ERAMSPMT/vm"
    },
    "item": "/vm"
}

MSG:

No folder /vm matched in the search path : /ERAMSPMT/vm

failed: [lxezfee1.eram.loc -> localhost] (item=/ZABBIX3) => {
    "changed": false,
    "details": {
        "datacenter": "SPMT",
        "datacenter_path": "/ERAM",
        "folder": "/ZABBIX3",
        "full_search_path": "/ERAMSPMT/vm/ZABBIX3"
    },
    "item": "/ZABBIX3"
}

MSG:

No folder /ZABBIX3 matched in the search path : /ERAMSPMT/vm/ZABBIX3

failed: [lxezfee1.eram.loc -> localhost] (item=ZABBIX3) => {
    "changed": false,
    "details": {
        "datacenter": "SPMT",
        "datacenter_path": "/ERAM",
        "folder": "/ZABBIX3",
        "full_search_path": "/ERAMSPMT/vm/ZABBIX3"
    },
    "item": "ZABBIX3"
}

MSG:

No folder /ZABBIX3 matched in the search path : /ERAMSPMT/vm/ZABBIX3

changed: [lxezfee1.eram.loc -> localhost] => (item=ERAM/SPMT/vm/ZABBIX3)
changed: [lxezfee1.eram.loc -> localhost] => (item=/ERAM/SPMT/vm/ZABBIX3)
...ignoring

So only /ERAM/SPMT/vm/ZABBIX3 and ERAM/SPMT/vm/ZABBIX3 are working for me.

@abhinav-chittora, you don't try with the fix #33337 which was only merged on the 28th of november on the ansible-devel branch. Your ansible version 2.5.0-devel is a little bit outdated (ansible 2.5.0 (devel 3d63ecb6f3) last updated 2017/11/24 13:16:25 (GMT +550)), update your version with:

pip install --upgrade git+https://github.com/ansible/ansible.git@devel

@Akasurde
Copy link
Member

@frado22 Could you please try this patch?

For setup Datacenter as root folder (aka with no folder)

→ python get_vm_path.py
dcpath /
Fifth
/ => /DC0/vm/
Found
********************************************************************************
Sixth
DC0 => /DC0/vm/DC0
********************************************************************************
Fifth
/DC0 => /DC0/vm/DC0
********************************************************************************
First
/DC0/vm => /DC0/vm
Found
********************************************************************************
Fourth
/vm => /DC0/vm
Found
********************************************************************************
Sixth
DC0/vm => /DC0/vm/DC0/vm
********************************************************************************

For nested folder (aka Datacenter under folder)

python  get_vm_path.py
dcpath /F0/
Fifth
/ => /F0/DC0/vm/
Found
********************************************************************************
Sixth
F0 => /F0/DC0/vm/F0
Found
********************************************************************************
Fifth
/F0 => /F0/DC0/vm/F0
Found
********************************************************************************
Fifth
/F0/vm => /F0/DC0/vm/F0/vm
********************************************************************************
Fourth
/vm => /F0/DC0/vm
Found
********************************************************************************
Sixth
F0/vm => /F0/DC0/vm/F0/vm
********************************************************************************

You can find the above script here. Let me know your findings.

@frado22
Copy link

frado22 commented Nov 30, 2017

@Akasurde

Result for datacenter SPMT :
iteration over : for folder in ['/', 'SPMT', '/SPMT', '/SPMT/vm', '/vm', 'SPMT/vm']:

output:

dcpath /ERAM/
Fifth
/ => /ERAM/SPMT/vm/
Found
********************************************************************************
Sixth
SPMT => /ERAM/SPMT/vm/SPMT
********************************************************************************
Fifth
/SPMT => /ERAM/SPMT/vm/SPMT
********************************************************************************
Fifth
/SPMT/vm => /ERAM/SPMT/vm/SPMT/vm
********************************************************************************
Fourth
/vm => /ERAM/SPMT/vm
Found
********************************************************************************
Sixth
SPMT/vm => /ERAM/SPMT/vm/SPMT/vm
********************************************************************************

with root folder ERAM:
iteration over: for folder in ['/', 'ERAM', '/ERAM', '/ERAM/vm', '/vm', 'ERAM/vm']:

output:

dcpath /ERAM/
Fifth
/ => /ERAM/SPMT/vm/
Found
********************************************************************************
Sixth
ERAM => /ERAM/SPMT/vm/ERAM
********************************************************************************
Fifth
/ERAM => /ERAM/SPMT/vm/ERAM
********************************************************************************
Fifth
/ERAM/vm => /ERAM/SPMT/vm/ERAM/vm
********************************************************************************
Fourth
/vm => /ERAM/SPMT/vm
Found
********************************************************************************
Sixth
ERAM/vm => /ERAM/SPMT/vm/ERAM/vm
********************************************************************************

@abhinav-chittora
Copy link
Author

@frado22 , yes, pulling latest changes, resolved the issue with complete path i.e. /Datacenter/AM-Datacenter/vm/DCOS but still using any other way for folder path, still doesn't work.

@Akasurde
Copy link
Member

@abhinav-chittora I am afraid, there is no other way to uniquely find virtual machine (yet). I am glad that your issue is resolved with complete path.

Could you please paste your PB here with variables and close this issue ?

@frado22
Copy link

frado22 commented Nov 30, 2017

Hi

@Akasurde

Maybe a solution (which works for me) is to change the documentation in order to say that for folder we have to set the folder path starting from the datacenter name.

I test this with your script (existing ZABBIX3 folder and without folder) :
for folder in ['ZABBIX3', '/ZABBIX3', '', '/']:
output:

dcpath /ERAM/
Sixth
ZABBIX3 => /ERAM/SPMT/vm/ZABBIX3
Found
********************************************************************************
Fifth
/ZABBIX3 => /ERAM/SPMT/vm/ZABBIX3
Found
********************************************************************************
Sixth
 => /ERAM/SPMT/vm/
Found
********************************************************************************
Fifth
/ => /ERAM/SPMT/vm/
Found
********************************************************************************

As we have to provide the datacenter, the folder path is correctly found.

@Akasurde
Copy link
Member

Akasurde commented Dec 2, 2017

resolved_by_pr #33479

@Akasurde
Copy link
Member

Akasurde commented Dec 6, 2017

@abhinav-chittora @frado22 I have opened new PR #33525 which is detects unique VM depending on UUID or NAME without the need of folder. Could you please try this and let me know if it works for you ?

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. cloud module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. vmware VMware community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants