Open Griamce0385 opened 2 years ago
Also occurs with Ansible 2.12
Thanks, @Griamce0385 for reporting the issue!
I tried setting the distributed port group name includes '%' to the network name to create a new vm, but I didn't occur the same error in my environment.
The below playbook is that I created.
---
- name: test
hosts: localhost
gather_facts: false
tasks:
- name: test
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
datacenter: "{{ datacenter }}"
cluster: "{{ cluster }}"
folder: "{{ folder }}"
guest_id: centos7_64Guest
name: "{{ vm_name }}"
hardware:
num_cpus: 1
memory_mb: 2048
networks:
- name: '10.0.0.0%2f24'
device_type: vmxnet3
connected: true
start_connected: true
datastore: "{{ datastore }}"
force: true
In my case, I got the below error.
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Network '10.0.0.0%2f24' does not exist."}
BTW, the below playbook works well
---
- name: test
hosts: localhost
gather_facts: false
tasks:
- name: test
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
datacenter: "{{ datacenter }}"
cluster: "{{ cluster }}"
folder: "{{ folder }}"
guest_id: centos7_64Guest
name: "{{ vm_name }}"
hardware:
num_cpus: 1
memory_mb: 2048
networks:
- name: '10.0.0.0/24'
device_type: vmxnet3
connected: true
start_connected: true
datastore: "{{ datastore }}"
force: true
My Environment Information
Please let me know several things.
vCenter Version: 7.0.3.00600 It is the name of the distributed port group.
Also I tested on Ansible version 2.12.6 this morning yielding similar results.
Thanks for providing the information.
I'm not sure, the cause of the error might have something to do with VCSA version.
I don't have VCSA 7.0.3 now, but I'll deploy it and try again.
@Griamce0385 @MallocArray Does this happen when you create a new or when you reconfigure an existing VM? It sounds like @sky-joker only tested creating a new VM. If you run into this issue when reconfiguring one, it might be a (slightly) different code path that we have to look at.
BTW: Is your network name really 19.18.17.0%2f24_VLAN999
? This looks a bit like you're trying to encode /
with %2f
. If I'm right, did you test plain 19.18.17.0/24_VLAN999
?
@mariolenz Yes, unfortunately a lot of our network names have "%2f" in the name as many of them are quite old and were created with old vCenter thick client using a "/". When we migrated to the H5 client names created with a "/" switched to "%2f" . We have newer networks with "/" in the name and those do work. The valid vCenter name for the port group is in fact "19.18.17.0%2f24_VLAN999" and that is what we have to pass to the module.
The right answer is to probably renamed the networks to something not containing a %. I would assume though there's a way to escape the "%" in the name, however trying every way and combination of escape charters I can think of, has yield either this error or an invalid network name.
10.0.0.0%2f24
Was your port group in vCenter named "10.0.0.0%2f24" or was it named "10.0.0.0/24"? In our case we have port groups using "%2f24" in the name.
I will give a supplementary explanation. Slash is displayed that is URL encoded in a VM summary of VCSA UI. So ‘/‘ is displayed as a ‘%2f’.
'%2f' decodes to ‘/‘ in the module, so please specify '/', not '%2f'.
FYI
Display in Network
Display in VM Summary
@Griamce0385 We encountered this problem in our environment. The port group is named with a '/', but it is url encoded to '%2f' internally in vCenter. When specifying the network, we needed to use the '%2f' and not the '/'. You need to make sure that the name, with the '%2f', is not being further url encoded before supplying it to the ansible module. In your example, this appears not to be the case.
What works for us is storing the name in a variable, specifically, we use a dict. You need to make sure that the '%' is not being interpreted as anything other than a character in the name. If you wish to avoid the issue all together, you must not use any special characters in the original name that url encode to anything requiring the '%' escape character.
We are currently running 6.7 without issue, so there may be a problem with 7.0's interpretation.
I will give a supplementary explanation. Slash is displayed that is URL encoded in a VM summary of VCSA UI. So ‘/‘ is displayed as a ‘%2f’.
'%2f' decodes to ‘/‘ in the module, so please specify '/', not '%2f'.
@sky-joker This works (playbook executed without errors), but Network not connecting to VM. :(
This is not a problem with the module, but with VMware. You need to do something like "{{ request.network | urlencode() | regex_replace('/', '%2f') }}". Where request.network is the name of the port group with the literal '/'. The problem is that VMware displays the '/', but requires the name to be encoded. You can actually see this behavior in vCenter itself.
Sent from my Verizon, Samsung Galaxy smartphone Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: n0ve1 @.> Sent: Tuesday, November 29, 2022 10:03:26 PM To: ansible-collections/community.vmware @.> Cc: Paul Knight @.>; Comment @.> Subject: Re: [ansible-collections/community.vmware] vCenter Port Groups with a '%' in the name result in an error (Issue #1361)
I will give a supplementary explanation. Slash is displayed that is URL encoded in a VM summary of VCSA UI. So ‘/‘ is displayed as a ‘%2f’.
'%2f' decodes to ‘/‘ in the module, so please specify '/', not '%2f'.
@sky-jokerhttps://github.com/sky-joker This works (playbook executed without errors), but Network not connecting to VM. :(
— Reply to this email directly, view it on GitHubhttps://github.com/ansible-collections/community.vmware/issues/1361#issuecomment-1331585042, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA2LV63C7IPBSQZGRPLSS3DWK27X5ANCNFSM5ZOL52DQ. You are receiving this because you commented.Message ID: @.***>
@n3pjk, I tried different ways of escaping/encoding, but then the error is that the network is not found (deploing a virtual machine from a template).
SUMMARY
When passing a network port group via a variable in module vmware_guest with a '%' character the module crashes
ISSUE TYPE
COMPONENT NAME
vmware_guest module at line 1871
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
EXPECTED RESULTS
I expect no errors and have the vm configured then go into the next play
ACTUAL RESULTS
VM is configured with proper port group, but there is an error and subsquent plays dont execute because this one fails