-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
Comments
@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
which is due to the fact that vmware_guest sets value of |
@Akasurde What should the user do if no folder is needed? Specifying an empty string or 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 I would be happy to do some git bisecting and help to find the specific cause of this error, if necessary. |
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 ---
- 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. |
@Akasurde My view is pretty simple: the |
@Akasurde So I spent a bit of time looking at 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 Nevertheless, I think that the key idea in this patch is that the default value of |
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.
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: / |
@cigamit Yeah, I suspected as such. However, when I tried to use Yeah, I gathered that Anyways, I think the issue at hand is trying to figure out why |
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 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. |
@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. |
@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:
More information from #20291 |
Hi @dagwieers Error msg: No folder matched the path: /Datacenter/AM-Datacenter/vm/DCOS" |
@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 Please use my walk script to validate the paths ... https://github.com/jctanner/ansible-tools/blob/master/vmware/vmware_walk.py
In your case, the filter would be "DCOS". needs_info |
I will use this script to find the path and use the path to create new virtual machine. I will update the result here. |
@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. |
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:
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 |
@frado22 Could you please paste your playbook ? |
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.
|
@frado22 I created similar setup in my environment
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 Could you please try - |
I test your fix in my environment. I duplicate the task in order that you see the result in one output:
Here is the result:
So your resolution is working for the full path, but not for the relative one, nor if I do not set any folder.
Notes:
|
@frado22 Just I expected. I will fix "missing /" issue. Also, I will try to backport this change in 2.4.x branch. |
@abhinav-chittora Could you please try adding folder as |
@abhijeet, sure. Let me test that and update the results here.
…--Regards,
Abhinav Chittora
Sent from my iPhone
On 29-Nov-2017, at 19:32, Abhijeet Kasurde ***@***.***> wrote:
@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 ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@Akasurde, I tried with /DCOS as folder but getting error that Here is the playbook execution results: -
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: -
I tested with other ansible version and getting following error: -
Even with latest ansible code, the error is same: -
And with complete path as
|
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:
So only @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 ( pip install --upgrade git+https://github.com/ansible/ansible.git@devel |
@frado22 Could you please try this patch? For setup Datacenter as root folder (aka with no folder)
For nested folder (aka Datacenter under folder)
You can find the above script here. Let me know your findings. |
Result for datacenter SPMT : output:
with root folder ERAM: output:
|
@frado22 , yes, pulling latest changes, resolved the issue with complete path i.e. |
@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 ? |
Hi 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) :
As we have to provide the datacenter, the folder path is correctly found. |
resolved_by_pr #33479 |
@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 ? |
ISSUE TYPE
COMPONENT NAME
vmware_guest
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
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.
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.
The text was updated successfully, but these errors were encountered: